Set Classpath in Manifest (Class-Path)

604 views
Skip to first unread message

Willie Owens

unread,
Jul 19, 2011, 5:22:20 PM7/19/11
to testng-users
Hi, I'm trying to run a simple test residing within a jar file, which
contains the test and manifest:

ex.) Test.jar contains:
{
META-INF\
META-INF\MANIFEST.MF
tests\
tests\Test01.class
}

I am trying to run it using the command: java org.testng.TestNG -
testjar Test.jar testng.xml

Where my folder structure is:
Test.jar
testng.xml
testng-6.1.1.jar

And Manifest contains (w/ a line-break at the end):
Manifest-Version: 1.0
Created-By: Willie Owens
Class-Path: testng-6.1.1.jar Test.jar .

And I get a NoClassDefFoundError: org/testng/TestNG. Could not find
main class.

If I specify the classpath using -cp after "java" (Ex. java -cp
testng-6.1.1.jar;Test.jar org.testng.TestNG -testjar Test.jar
testng.xml) it works, but I want this information in the manifest.
What am I doing wrong here?

Willie Owens

unread,
Jul 20, 2011, 12:33:04 PM7/20/11
to testng-users
Is there anyone that can help? This seems like it should be a simple
problem, but nothing seems to work. For the classpath in the manifest
I've tried ./testng-6.1.1.jar, .\testng-6.1.1.jar, and all other
variations with no luck...

Simon Knott

unread,
Jul 20, 2011, 2:13:50 PM7/20/11
to testng...@googlegroups.com
Hi,

Your command line syntax looks a little wrong:

java org.testng.TestNG -testjar Test.jar testng.xml 

Should read:

java org.testng.TestNG -jar Test.jar testng.xml 


I believe if you then put the ./testng-6.1.1.jar in your manifest, it should work.

Cédric Beust ♔

unread,
Jul 20, 2011, 2:44:28 PM7/20/11
to testng...@googlegroups.com
Actually, no, the command that TestNG recognizes is indeed "-testjar", not "-jar" (I named it this way to avoid the confusion with java's own "-jar" option).

-- 
Cédric




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Gr1GPn5zyYcJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Willie Owens

unread,
Jul 20, 2011, 5:10:10 PM7/20/11
to testng-users
So... am I doing everything right then? Is there anything to do with
TestNG that could be causing this? Could anyone test this one out?
Here I am just trying to print out 'Hello World!' to the console..

Cédric Beust ♔

unread,
Jul 20, 2011, 5:15:52 PM7/20/11
to testng...@googlegroups.com
Hi Willie,

There are some sadly well known bugs with -jar and MANIFEST files, I wonder if you're not running into one of these. I suggest looking up this issue (probably answered on StackOverflow).

Let me know what you find out.

-- 
Cédric

Willie Owens

unread,
Jul 20, 2011, 5:47:39 PM7/20/11
to testng-users
Nothing..

On Jul 20, 2:15 pm, Cédric Beust ♔ <ced...@beust.com> wrote:
> Hi Willie,
>
> There are some sadly well known bugs with -jar and MANIFEST files, I wonder
> if you're not running into one of these. I suggest looking up this issue
> (probably answered on StackOverflow).
>
> Let me know what you find out.
>
> --
> Cédric
>

Simon Knott

unread,
Jul 20, 2011, 7:13:00 PM7/20/11
to testng...@googlegroups.com
Ah, I didn't know that!  However, how is TestNG going to recognize the -testjar command, if the TestNG class is being loaded through the manifest of the Jar which hasn't been referenced yet? ;)

Simon Knott

unread,
Jul 20, 2011, 7:22:17 PM7/20/11
to testng...@googlegroups.com
Sorry, I'm a bit too tired and I've realised that doesn't make a lot of sense.

The TestNG class can only be loaded if the Test.jar is referenced in the Java classpath, which requires the -jar option.

Have you tried the following command, which is probably uglier than you were hoping:

java -cp Test.jar TestNG -testjar Test.jar testng.xml

Simon Knott

unread,
Jul 20, 2011, 7:24:27 PM7/20/11
to testng...@googlegroups.com
My kingdom for an edit button....

java -cp Test.jar org.testng.TestNG -testjar Test.jar testng.xml

Willie Owens

unread,
Jul 20, 2011, 8:08:42 PM7/20/11
to testng-users
You, my good sir are awesome! Thank you, that fixes it!

I'd been dying on this problem. What I had tried was referencing just
the testng-6.1.1.jar with the -cp switch, and I still got a
classnotfound exception on my test class. I figured Test.jar would be
in the classpath already because that is being referenced in the
command. I had even tried adding Test.jar itself to the classpath in
the manifest, but I suppose it couldn't get there.

Thanks again, really.

Cédric Beust ♔

unread,
Jul 20, 2011, 8:18:30 PM7/20/11
to testng...@googlegroups.com
Yup, you need to specify the jar file twice: once for Java so it can find your classes and one for TestNG so it can find your testng.xml.

-- 
Cédric




--
You received this message because you are subscribed to the Google Groups "testng-users" group.

Willie Owens

unread,
Jul 20, 2011, 8:33:48 PM7/20/11
to testng-users
Gotcha, thanks.

On Jul 20, 5:18 pm, Cédric Beust ♔ <ced...@beust.com> wrote:
> Yup, you need to specify the jar file twice: once for Java so it can find
> your classes and one for TestNG so it can find your testng.xml.
>
> --
> Cédric
>
Reply all
Reply to author
Forward
0 new messages