Results 1 to 5 of 5
- 01-16-2011, 07:41 PM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
cannot find the class file when running the java command
hello, thanks for reading.
I am an eclipse user and running files(classes) from the terminal was a bit forgotten to me.
tried to play with my terminal but it gets me to a situation where I had no clue.
I can do the java command 'javac Hello.java'. it reads for a while and then suddenly you have a .class file in the place where the .java file exists but when I do the the javac like 'java Hello', it would say
I believe I have the classpaths set because I can invoke the 'javac' command. and my classpath isJava Code:Exception in thread "main" java.lang.NoClassDefFoundError: Hello
JAVA_HOME=/usr/lib/jvm/java-6-openjdk:/usr/lib/jvm/java-6-openjdk/bin
CLASSPATH=$TOMCAT_HOME/lib:$TOMCAT_HOME:$JAVA_HOME
I even copied the Hello.class file to the same directory where the java command lies. in the bin directory and it would still give me that friendly message
so I am bit clueless right now, do I have something wrong with my paths? or maybe with the files I am creating?
Any suggestions would be appreciated :D
regards,
simon
- 01-16-2011, 07:47 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
update:
tried to do the command "java -classpath . Hello" and it worked. I was wondering why it was no able to act upon the classpath that I set on my system variable?
- 01-18-2011, 06:36 AM #3
The environment variable settings are normally used by the command processor to search for the executables and batch files, like *.exe and *.bat files. So when you type "java", it actually goes to your java installations bin directory, where it finds the java.exe and it executes the further things.
If you have placed your generated .class file inside the bin directory [which is in environment variable], then you would have to explicitly mention the class path for that file using the -cp or -classpath option. In your case, on a windows machine you would have to run,
which would run your program correctly.Java Code:java -cp "%path%" Hello
One more thing, whenever you specify the -cp or -classpath option along with java, it overrides the classpath environment variable settings declared.
Hope that helps,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-18-2011, 10:59 AM #4
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
Hi,
That was too much help, now I understand. Thanks for replying :D
regards,
simon
- 01-18-2011, 11:34 AM #5
Similar Threads
-
error in the Command Prompt when running a bat file
By bluesagemedia in forum New To JavaReplies: 1Last Post: 10-03-2010, 01:05 AM -
"Could not find the main class" for Linux Command Line Compile
By tetelee in forum New To JavaReplies: 3Last Post: 08-25-2010, 10:21 AM -
running command prompt using java
By xclaim in forum New To JavaReplies: 1Last Post: 01-14-2010, 03:46 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks