It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Class path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class path" Watch "Class path" New topic
Author

Class path

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I have the following set in my unix path and classpath
PATH=/ora/pofd/pofddb/8.1.7/xdk/java/parser/bin/:/ora/pofd/pofddb/8.1.7/xdk/lib/
:/ora/pofd/pofddb/8.1.7/lib/:/ora/pofd/pofddb/8.1.7/xdk/bin/:/ora/pofd/pofdcomn/
util/jre/1.1.8/lib/:/ora/pofd/pofdcomn/util/jre/1.1.8/bin:/usr/java131/jre/lib:/
usr/java131/lib:/usr/java131/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr
/bin/X11:/sbin:/bin:/work/scripts:/usr/ibmcxx/bin:/work/vsubra/fullsaxon:.
export PATH
CLASSPATH=/ora/pofd/pofdcomn/util/jre/1.1.8/libi18n.jar:/ora/pofd/pofdcomn/java/
xmlparserv2.zip:/work/vsubra/fullsaxon/saxon.jar:/work/vsubra/fullsaxon/saxon-fo
p.jar:/usr/java131/jre/lib/rt.jar:/usr/java131/lib/tools.jar:.
export CLASSPATH

when i create a file A.java while running it with java A
it gives me the following error:
Exception in thread "main" java.lang.noclass defn found.
I have given rt.jar in my path. What am I missing?
Thanks,
Vidhya
Chris Hall
Ranch Hand

Joined: Dec 04, 2002
Posts: 39
I am not sure where to start based on your question....but here is a shot. First off, you know you must compile the A.java file to create a A.class file. Use the javac command to do this. Once you have created A.class, you execute this by typing java A (assuming you are not specifing a package). At the execution point, you must have the directory containing A.class on your classpath. Since you have . on your classpath, you can execute the java command from the directory containing A.class and everything should work.
Hope this helps.
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I am in my root directory /work/vsubra. I have file A.java in this directory. When I compile useing javac A.java it does create a class in the same dir as A.class. But when I run it using java A then it gives me this error
Exception in thread "main" java.lang.NoClassDefFound error
i have given the path in my classpath also for rt.jar. The path goes as
/usr/java131/jre/lib/rt.jar;.
Why this error then?
Thanks,
Vidhya
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
Hi,
Do u use package in u'r Java program? If u use package, then u have to set that in u'r CLASSPATH, or else set the CLASSPATH=.;
----------
Nayan
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
if you have used a 'package' line in your program, e.g.
package com;
public class A{
// ...
}
and your 'A.java' is in '/work/vsubra', your file compiles but will not run.
You should create the package directory '/work/vsubra/com' (i.e. depending on the name of your package) and place your A.class file at '/com',
then run 'java com.A in '/work/vsubra'
check also if you have a 'main' method of the right signature.
hope this helps.
Chris Hall
Ranch Hand

Joined: Dec 04, 2002
Posts: 39
The reason for the NoClassDefFoundError is that it can't find your Class. With . on you classpath, you must make sure you are in the same directory as A.class when executing the 'java A' command. If you specified a package, refer to the previous post as to how to execute the java command and where to make sure your A.class is located.
At this point we can't tell if there is anything wrong with the actual code, since the error states it can't find it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Class path