| Author |
Classpath problem
|
Suwen Meng
Greenhorn
Joined: Feb 03, 2002
Posts: 3
|
|
hi I have a problem on setting classpath. I'm using Win XP. I put jdk1.3.0_02 in d:\java\jdk1.3, and I set classpath=,;d:\;d:\java\jdk1.3\lib\tools.jar;d:\java\jdk1.3\jre\lib\rt.jar. Coz I have some pre-defined classes in d:\java\javabook, I set above "d:\;". These classes are all *.class in the directory, not *.jar,etc. When I run my java program, "javac *.java". (in the first line of this program is "import javabook.*;") I can compiled it and find "*.class" existed in the directory. But when I run "java *", there are some error message: "Exception in thread "main" java.lang.NoClassDefFoundError:* (wrong name:*) Can anyone help me with this? Thanks Suwen
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Well, firt off, there is no need to set the classpath for JDK1.3 and above except for 3rd party classes or your custom classes that you want to import. The compiler knows where to find the classes it needs. Second, if your classes are in d:/foo/foofoo then you should specify that in your classpath either at compile time or set it to do it for you in an IDE or editor you are using if it has that functionallity. Third, you should specify that path to the class files you need, not just the drive on which they exist. CLASSPATH = D:\; - WRONG CLASSPATH = D:\foo\foofoo; - RIGHT Hope that helps some.
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
In your classpath you need to have: d:\java\jdk1.3\lib In addition you need to have: d:\java\javabook so that it will pick up your .class files. You should also have a . reference (not a comma like you have shown)- which will tell the system to pick up any class file that are in the same directory that you are sitting in when you call java.exe. So all together: classpath=.;d:\java\jdk1.3\lib;d:\java\javabook; Try that. Also Suwen, Please change your displayed name to be compliant with JavaRanch's naming policy. Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name. Thanks, Cindy [ February 28, 2002: Message edited by: Cindy Glass ]
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Gregg is right - there should be no need to put d:\java\jdk1.3\lib in your classpath; the JVM already knows about it. If it didn't, then you would need to specify each jar file by name as well - not just the name of the directory that contains them. Suwen, have you declared any packages in your classes? For example, if the classes in d:\java\javabook are declared to be in the javabook package (implied by your "import javabook.*" elsewhere), then your classpath needs to include "d:\java" but not "javabook". Basically, the classpath needs to point to the directory where the package structure starts.
|
"I'm not back." - Bill Harding, Twister
|
 |
Suwen Meng
Greenhorn
Joined: Feb 03, 2002
Posts: 3
|
|
hi All Tnank you for giving me lots of help. According to your suggestion. I changed the classpath: set classpath = .; d:\java\; According to Jim's suggestion, I have "import javabook.*" in the program, (Do I need specify d:\java\javabook ?) and I compile the program in d:\ directory, but the problem is still same. Thanks for your attention.
|
 |
jacq carballo
Ranch Hand
Joined: Feb 10, 2002
Posts: 42
|
|
Exception in thread "main" java.lang.NoClassDefFoundError:* I also experience the same problem whenever i do try to set my classpath. Maybe something i am doing incorrectly. You could remove the problem by not setting the classpath at all. This might be a temporary solution, but it will work as it did for me dozens of times already. Jacq
|
 |
Suwen Meng
Greenhorn
Joined: Feb 03, 2002
Posts: 3
|
|
hi jacq carballo yes, it works without setting classpath. It seems strange. How does the program look for the imported class? :roll:
|
 |
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
|
|
What class did you name *? java.exe needs to know the fully qualified name of the class you want to execute. Wildcards are NOT permitted! So: java the.packagename.classfilename Should work but java * Will never work even if there is only 1 class file present!
|
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
|
 |
 |
|
|
subject: Classpath problem
|
|
|