Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Class path

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I have the following set in my unix path and classpath
export PATH

when i create a file 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?
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 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 in this directory. When I compile useing javac 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
Why this error then?
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
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=.;
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 '' 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.
I agree. Here's the link:
subject: Class path
It's not a secret anymore!