Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Fun runtime issues!

 
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
 
Ranch Hand
Posts: 1282
  • 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
 
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.
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!