Run Junit test class inside one-jar with junit outside the jar

Mr_and_Mrs_D picture Mr_and_Mrs_D · Jan 26, 2013 · Viewed 11k times · Source

So I have packed my classes and their dependancies (apache commons cli) inside a jar file using one-jar (which was easy enough to do, see section Command-Line Approach). Now I am curious if I can run the java test class inside the jar using a Junit jar outside the class. So the path to the test class inside sw.jar is :

sw.jar\main\sw.jar\uoa\di\ys11\hw2\TestSmithWaterman.class

(the main\ is a one-jar thing). I have tried variations of :

java -jar -cp lib/junit.jar org.junit.runner.JUnitCore  uoa.di.ys11.hw2.TestSmithWaterman

with no luck - so what would the command line be ? Or do I need to modify the one-jar manifest somehow ?

EDIT : the /boot-manifest.mf:

Manifest-Version: 1.0
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: uoa.di.ys11.hw2.Hw2

while the /META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Created-By: 1.7.0_09 (Oracle Corporation)
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: uoa.di.ys11.hw2.Hw2

Answer

Roman C picture Roman C · Jan 26, 2013

Use the following command line to test

java -cp lib/junit.jar;sw.jar org.junit.runner.JUnitCore  uoa.di.ys11.hw2.TestSmithWaterman

EDIT:

this should be work with normal jars, but the jar is created by the one-jar

One-JAR lets you package a Java application together with its dependency Jars into a single executable Jar file.

After that it's not possible for junit, as I mention junit-4.4 in my case to load such classes for test.