• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems with CLASSPATH

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

I'm pulling my hair out trying to figure this out. I'm creating a program using the Netbeans IDE and was gong to send off the class files to a friend so they could run the program. So I just wanted to make sure I could get the program to run on the command line. For some reason I can compile and run the program within the IDE but when I try on the command line I get the following message after runing "java -classpath . Main" :



My classpath contains the directory the files are located in and the current directory '.'

Does anybody have any idea as to why this is happening? I feel rather retarded. Thanks.

Andreas
 
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andreas!

I don't know which classes you need to run your programm but by defining -classpath . you reset the classpath variable of your shell or dos-box. Try -classpath $CLASSPATH;. for Windows or -classpath $CLASSPATH:. for Linux systems to add the current directory to your classpath.

Ernie
 
Andreas Sandberg
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernie, I'm still having some issues. I find it strange that running: 'java fakeclassname' only produces the output NoClassDefFound yet when I invoke 'java Main' I get the stack trace. By the way, I can still run the class file with the .jar file from the netbeans IDE on the command line yet when I unzip the .jar file and try to run java on the main class it blows up.
 
Andreas Sandberg
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,

I removed the package statments from the two java files and everything wokrs fine now. For some reason I kept the java files in the following directory:

/home/andreas/tmp

and had the package statement set in both source files as :

package home.andreas.tmp;

Anybody have any ideas as to why this would be a problem with running the command "java -classpath . Main"

Thanks!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andreas, look closely at the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: home/andreas/tmp/Main)

Do you have a package statement ("package home.andreas.tmp;") in your source file? If so, you should have put your class file in the right directory structure (.../home/andreas/tmp) and you should have put the directory that contains the "home" directory in the classpath.

Have a look at these pages:
How Classes are Found
Setting the class path

(edit): Ah, you already discovered it yourself...
[ November 04, 2005: Message edited by: Jesper de Jong ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic