Question: 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.

Answer: 
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.

> 
> login@domain:~/temp> mkdir src  
> 
>  login@domain:~/temp> cd src  
> 
>  login@domain:~/temp/src> mkdir junitfaq  
> 
>  login@domain:~/temp/src> nano junitfaq/SimpleTest.java
> 
> 
> 

The contents of SimpleTest.java are as follows when I exit nano:

```
package junitfaq;

public class SimpleTest {
        public static void main(String[] args) {
                System.out.println("Test");
        }
}

```

> 
> login@domain:~/temp/src> javac junitfaq/SimpleTest.java  
> 
>  login@domain:~/temp/src> java junitfaq.SimpleTest  
> 
>  Test
> 
> 
>
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!