 |
 |
problem with UNIX classpath and java package directive
|
 |
|
 |
|
Registered User
Join Date: Jan 2003
Location: New Brunswick, NJ
Status:
Offline
|
|
I cant get java's package directive and UNIX to jive and I've been looking online for an explanation. I must be doing something very small incorrectly. Does anyone have any suggestions?
the name of the program is ThreadDemo.java and it's in the following folder:
/Users/bschilke/Documents/Computers/programming/Java/JavaByExample/JavaExamples2/com/davidflanagan/examples/thread
i have a file called ~/.tcshrc with the below line to set the pathname:
setenv CLASSPATH .:/Users/bschilke/Documents/computers/programming/java/JavaByExample/JavaExamples2
the package name in the program:
package com.davidflanagan.examples.thread;
so when I'm in /thread/, i can compile, but when i try to run the program ('java ThreadDemo'), I get:
Exception in thread "main" java.lang.NoClassDefFoundError: ThreadDemo (wrong name: com/davidflanagan/examples/thread/ThreadDemo)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :488)
at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:106)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:243)
at java.net.URLClassLoader.access$100(URLClassLoader. java:51)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 190)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:183)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 94)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:281)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 50)
Anyone have any suggestions?
(Last edited by sidecar71; May 18, 2003 at 09:53 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
If the examples are in a jar file then your classpath needs to include that jar i.e.,
/Users/bschilke/Documents/Computers/programming/Java/JavaByExample/JavaExamples2/com/davidflanagan/examples.jar
If you have a bunch of loose .class files in a folder then you need to include the folder itself.
/Users/bschilke/Documents/Computers/programming/Java/JavaByExample/JavaExamples2/com/davidflanagan/
Just think of the jar as a directory.
Another thing to watch out for is non Unix text format for the .java source files. Get something like BBedit and turn the "show invisible characters" option on and see if all is well.
Let me know how it goes.

|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status:
Offline
|
|
you need to call java com.davidflanagan.examples.thread.ThreadDemo instead of java ThreadDemo. The reason is because the classloader is looking for a class with a fully qualified name of 'ThreadDemo', but all it finds is one with the name 'com/davidflanagan/examples/thread/ThreadDemo'
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
Originally posted by itai195:
you need to call java com.davidflanagan.examples.thread.ThreadDemo instead of java ThreadDemo. The reason is because the classloader is looking for a class with a fully qualified name of 'ThreadDemo', but all it finds is one with the name 'com/davidflanagan/examples/thread/ThreadDemo'
I second this. Your classpath specified both the current directory "." and the full path to the package root. When your current directory and the package root are the same it will find the classfile under "." first and will expect the file to be in the default package which it is not. Of course, if you specified the correct class name (with the package) this wouldn't have been an issue.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |