I know this question has already been answered many times, but unfortunately I couldn't find the right answer to my questions.
below is my package structure and inside my package I have SimpleTest.java
d:\junit\src\junitfaq\SimpleTest.java
inside d:\junit\src> i tried to compile SimpleTest.java and it successfully compiled using the command below.
d:\junit\src>javac junitfaq/SimpleTest.java
but when i try to run the program using command line below
d:\junit\src>java junitfaq.SimpleTest
this error occured. Error: Could not find or load main class junitfaq.SimpleTest
I tried running it by accessing junitfaq package by using this command
d:\junit\src\junitfaq>java -cp . SimpleTest
the program run perfectly. A little help would be much appreciated.
trialYou could try putting your java and class files together with your libaray folder (if any) in a new file called "trial" in your C:\ directory then compile existing java file using the following->
C:\trial> javac -cp .;library folder* SimpleTest.java
(then)
C:\trial> java -cp .;library folder* SimpleTest
Let me know how you get on!
Have you declared your SimpleTest class to be a member of the junitfaq package? If you have, you should be able to run it from the src directory like
java junitfaq.SimpleTest
but you should get an error like this if you try to run it from within the junitfaq directory:Exception in thread "main" java.lang.NoClassDefFoundError: SimpleTest (wrong name: junitfaq/SimpleTest)
Make sure your SimpleTest class starts with
package junitfaq;
Edit: Here's a working example incorporating the comments below.
The contents of SimpleTest.java are as follows when I exit nano:
It sounds like you have a classpath problem; you should double-check the location of your class file, the directory/package structure, the location from which you're trying to run the java command, and any classpath specified during execution.
For example, the following works for me:
Not to belabor the obvious, but I noticed a spelling typo in one of your comments - you should also double-check that you're running the command as intended.