Exception in thread "main" java.lang.NoClassDefFoundError: junit/framework/Test

1,698 views
Skip to first unread message

arundev

unread,
Feb 1, 2012, 6:34:28 AM2/1/12
to Selenium Users
Hi,

I use eclipse ide and selenium rc.
When i export the TestSuite as jar i am getting the following
exceptions.
Exception in thread "main" java.lang.NoClassDefFoundError: junit/
framework/Test
at
com.selftechy.testsuite.commonBrowser.main(commonBrowser.java:46)
Caused by: java.lang.ClassNotFoundException: junit.framework.Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 1 more
----------------------------------------------------------------------------------------------------
My test Suite code:-
---------------------------------
package com.selftechy.testsuite;
import junit.framework.Test;
import junit.framework.TestSuite;
public class RunTestSuite {

public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(Test1.class);
suite.addTestSuite(Test2.class);
suite.addTestSuite(Test3.class);
suite.addTestSuite(Test4.class);
return suite;
}

public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}

The code works fine in eclips and ANT.

Thanks
Arun Dev

Lutfi Dughman

unread,
Feb 1, 2012, 11:20:48 AM2/1/12
to seleniu...@googlegroups.com
show us the command line you ise to execute this.

the cause for such thing usually ahs to with the fact that the jar file is not in the classpath where the JVM looks up for classes.

in other words you have to tell the JVM where to look when loading classes.

ex:

java -cp "c:\file1.jar;cL\file2.jar" com.my.class.with.main.method


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


arundev

unread,
Feb 8, 2012, 5:29:13 AM2/8/12
to Selenium Users
Hi,,

I have all my libs in my D:\libs folder
i also placed my jar file in the same directory.
junit jars version:-
junit-4.10.jar
junit-4.10-dep.jar

in the cmd i use java -jar d:\libs\myjar.jar(my Testsuite jar)
i tried using java -classpath d:\libs\junit-4.10.jar -jar d:\libs
\myjar.jar.

both did not work...please help me with cmd command with above
referance

(My knowledge in java is very limitted)

Thanks in advance

Krishnan Mahadevan

unread,
Feb 8, 2012, 5:47:57 AM2/8/12
to seleniu...@googlegroups.com
You are confusing yourself with the approach here.

java -jar ----> This essentially ignores any classpath settings and just proceeds with finding everything within the jar that you are providing.

java -cp ---> If this form is used, you would specify all the jars that are to be referred by java as ";" separated (In Windows)/ ":" (In Non Windows) and then provide the class that contains the main() method so that Java can invoke it. Alternatively if your jar "myjar.jar" in this case, has a manifest file (which is some thing like a meta data file, which will contain information pertaining to what is the class that needs to be invoked to run the main method) you can skip specifying the class name that contains the main method which you want to be invoked.

For e.g., selenium-server-standalone-2.18.0.jar has a manifest file under META-INF folder as defined below

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0-google-v4-55908-24403953 (Sun Microsystems Inc.)
Main-Class: org.openqa.grid.selenium.GridLauncher

Name: Build-Info
Selenium-Version: 2.18.0
Selenium-Revision: 15704
Selenium-Build-Time: 2012-01-27 15:48:16


So here if you see, we are telling java that it needs to by default invoke the main() method that resides within org.openqa.grid.selenium.GridLauncher



Disclaimer : This is all based on my limited understanding of how things work :)


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
Reply all
Reply to author
Forward
0 new messages