2

I'm a software tester. We're providing a JAR file to our customer and it happened the second time now that the JAR file does not contain all needed classes. I don't know how that can happen from development point of view since I assumed that Eclipse would always add all classes to the JAR file.

Anyway, is there a tool that can check the integrity of a JAR file with the following requirements:

  • gets all new statements in the JAR (by reflection?) and checks whether the class can be resolved
  • runs on Windows (specifically 7 SP1 x64)
  • is free / gratis, open source preferred

Update

The way I'm thinking of this tool is

C:\>checkjar.exe myjar.jar
Checking JAR file integrity ...
Class org.mycompany.MyClass is referenced by org.mycompany.MyApp.doSomething(String args) but the class does not exist

I don't need

  • a tool to run JUnit tests, since we don't have unit tests at the moment. I'm working on that.
  • a tool to run integration tests. I confess, we don't have one yet, but we just need to pick one from the available.

Eventually it will be a task to integrate the JAR checker tool into JUnit tests or something. Right now, I just have the JAR and I need a tool to check it for missing classes. Any more detailed tests will probably be realized as JUnit tests.

1

Building packages using the IDE is not considered to be a good practice nowadays. It is error-prone because it is a manual process. (You can read more on state-of-the-art software development in Head First Software Development.)

You should use a build tool like Maven or Gradle for building the project/Jar. This makes the build process repeatable and reliable. I guess that this will already solve your problem, because you don't rely on the developer to check the correct checkboxes when building the Jar in the IDE. Once a class is inside the generated Jar it will always be inside the generated Jar.

Additionally you may automatically run an integration test against the Jar. Start with a test that only executes the Jar. More details about running integration tests with a Jar can be found here: http://blog.sonatype.com/2009/06/integration-tests-with-maven-part-1-failsafe-plugin/

| improve this answer | |
  • We don't have integration tests - maybe I should have noted that in my question, sorry. One of the first integration tests I like to achieve is the mentioned missing classes test. – Thomas Weller Jul 2 '15 at 7:14
  • Then follow my advice ;-) – Stefan Birkner Jul 2 '15 at 7:19
  • Perhaps I didn't understand your answer... Failsafe will run tests after the package phase. I don't need that, because I currently run tests manually, which is also after the package phase. Surefire will run JUnit tests. I don't have JUnit tests. Maven will run JUnit tests. Dito. Sorry, at the moment I cannot see how your answer provides a tool to check a JAR file for new statements. – Thomas Weller Jul 2 '15 at 7:46
  • I reworked my answer, because I guess the problem could be avoided with proper tooling. (A goal of automatic tests is to find faults before you start the manual test and thereby don't waste your valuable time.) – Stefan Birkner Jul 2 '15 at 9:36
0

I would suggest a test setup consisting of a virtual machine containing just windows, or a minimal Linux, and java and testing your jar runs on there, (you can restore from a snapshot after each run to ensure that it runs OK).

VirtualBox is one good free virtual machine and if you test under Linux, (the jar files should run on Linux as readily as Windows), you will not need an OS licence.

| improve this answer | |
  • I'm working on test automation using virtual machines already. Until we have those tests (it will take ~12 months) testing the JAR completely (all paths) for missing classes is impossible. Therefore I thought reflection could at least do a 100% missing classes test. – Thomas Weller Jul 2 '15 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.