Re: "NoClassDefFoundError"Problem

163 views
Skip to first unread message

Kevin de Boer

unread,
Nov 8, 2012, 4:43:37 AM11/8/12
to fishe...@gmail.com, robotframe...@googlegroups.com
Hi there, nooby java user here who had the same problem.

NoClassDefFoundError in human language: The class was available during compiling, but not on runtine.

This most likely due to your .jar files are not set in the CLASSPATH. You should google how to set .jars in your classpath, as I am not an expert on that ;)

I assume you use something like eclipse to compile/jar your project, which does lots of magic for you, like adding the jars with all the dependencies. Thats why it will compile without errors.

However when you run it in robot, it no longer knows where the .jar files are that were used for importing some classes. In other words, the class existed during compiling, but it cant find it on runtime.

By adding your jars to the classpath, robot will search the classpath for your classes.

I have encountered this problem myself and I fixed it on my own machine by setting the classpath.
 

Atleast, thats my theory behind it ^^ I don't know if a java expert can confirm this. But it worked for me :D


On 8 November 2012 09:11, Fisher Ren <fishe...@gmail.com> wrote:
Hi,

I'm a tester in China and i'm quite new with ROBOT. I'll try my best to explain the problem with my poor English:(
I write a Java Class to test a Java Project, and when i use jybot to run my test code, "NoClassDefFoundError"Problem occurs.

The Java Project is like this:
./main.jar
./lib/xxx.jar...(many jars,which main.jar relies on)
./config/xxxx.property(main.jar runs depends on this property file)

My Java Class is a independent code, it contains a test.java file, and a lib directory which main.jar and many other relied jars in the Java Project in it.
In the test.java file, it calls some functions or classes defined in main.jar, so i can do the Business Logic Testing.It runs successfully in Eclipse.
Then i add my test project directory to system environment variable classpath, take test.java as a liberary in robotframework, and run it with jybot.
But "NoClassDefFoundError" problem appears.

Please help me to know why this problem happens and how do i do to test the Java Project.Thanks:)

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/9lKsWpzwdUkJ.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Fisher Ren

unread,
Nov 8, 2012, 5:32:16 AM11/8/12
to robotframe...@googlegroups.com, fishe...@gmail.com
i've tried to set .jar files in the CLASSPATH, but it doesn't work.(in windows)
now i do the same in linux, it works!
i'm ashamed about this simple problem...:(

your theory really helps, thank you :)

在 2012年11月8日星期四UTC+8下午5时43分42秒,Kevin写道:

Kevin O.

unread,
Nov 8, 2012, 8:52:40 AM11/8/12
to robotframe...@googlegroups.com, fishe...@gmail.com
I bet it is something simple you are missing, like accidentally using colons instead of semi-colons or a space at the beginning or skipping the current directory. Do an echo %CLASSPATH% and look really closely.

Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:
  • For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
  • For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
  • For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

Classpath entries that are neither directories nor archives (.zip or .jar files) are ignored.

Reply all
Reply to author
Forward
0 new messages