This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problems with CLASSPATH  RSS feed

 
Andreas Sandberg
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!