• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packaging question

 
Gil Steidle
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to understand java packaging and cannot get this to work. The java class is in c:\com\myapps and declared in the 1st line of code. What am I not doing correctly???

Thanks for the help!





C:\com\myapps>javac HelloWorld.java

C:\com\myapps>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong nam
e: com/myapps/HelloWorld)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: HelloWorld. Program will exit.

C:\com\myapps>dir
Volume in drive C has no label.
Volume Serial Number is 4449-5A9A

Directory of C:\com\myapps

12/08/2010 09:32 AM <DIR> .
12/08/2010 09:32 AM <DIR> ..
12/08/2010 09:45 AM 444 HelloWorld.class
12/08/2010 09:32 AM 140 HelloWorld.java
2 File(s) 584 bytes
2 Dir(s) 58,300,485,632 bytes free

C:\com\myapps>

 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You ought to run it from outside the package structure with java com.myapps.HelloWorld. So you will have to navigate to the root folder first.
It might be better to have a "java" folder, rather than working on the root of "C".
 
Gil Steidle
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, moving to the root directory allowed the program to run without complaining. Thanks.

Where can I find a source for some further explanation about what's going on here? Specifically, why couldn't I run the program from the source directory? Isn't the package declaration giving the location of the class? And the class was there but java couldn't find it??? So confused.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the Java™ Tutorials?
 
Gil Steidle
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have read the Java Tutorials on Packages and it helped a bit, but it did not help me with my question:
why couldn't I run the program from the source directory?



Also, if I follow your suggestion of:
It might be better to have a "java" folder, rather than working on the root of "C".

Would my directory structure then look like, c:\java\com\myapps?

Thanks!
Gil
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gil Steidle wrote:Ok, I have read the Java Tutorials on Packages and it helped a bit, but it did not help me . . .
Sorry. Anybody else know where you can find information? I couldn't find much in the Java™ Language specification.
. . . Would my directory structure then look like, c:\java\com\myapps? . . .
Yes.

And you're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic