Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fun runtime issues!

 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've developed some java code in the NetBeans IDE 4.1, it compiles and runs fine in NetBeans.

I want to try to run to same code via command line. I get this message:

Exception in thread "main" java.lang.NoClassDefFoundError: testproject/build/cla
sses/testproject/testprog (wrong name: testproject/testprog)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Pretty common issue on these forums, so I researched what people did to fix them. I checked my class path variables (both user and system), they are both:
C:\Netbeans_projects\

The class file (testprog.class) is saved in this directory:
C:\NetBeans_projects\TestProject\build\classes\testproject\

I go to the c:\NetBeans_projects directory and type:
java testproject.build.classes.testproject.testprog

And I get the error above, I've also tried:
java testproject/build/classes/testproject/testprog
java testproject\build\classes\testproject\testprog

None of them work.

Also, I've tried to compile the java file (testprog.java), saved at:
C:\NetBeans_projects\TestProject\src\testproject\
via command-line. It works, but saves the .class file in the src directory instead of the build directory. (But thats a separate issue)

Any idea of what I'm forgetting?

Thanks
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does your file has a package declaration?

if no, you cant type:
>java testproject\testprog, but just
>java testprog

BTW: use capital letter at begining of class name, like Testprog.java, or, for sake of readability, TestProg.java
 
Arjun K
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Taken From : David Miranda
It works, but saves the .class file in the src directory instead of the build directory. (But thats a separate issue)


javac -d d:/projects/testproj/build testproject.java

This will save the class file in build directory.

Regards,
Arjun K.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic