Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > problem with UNIX classpath and java package directive

problem with UNIX classpath and java package directive
Thread Tools
Registered User
Join Date: Jan 2003
Location: New Brunswick, NJ
Status: Offline
Reply With Quote
May 17, 2003, 12:41 PM
 
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
Reply With Quote
May 20, 2003, 01:32 PM
 
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
Reply With Quote
May 20, 2003, 02:23 PM
 
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
Reply With Quote
May 21, 2003, 01:51 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2