0

I managed to successfully compile my code, but I'm not able to execute it. How do I fix this? scannerTesting is my package and ScannerTesting.java is my main file.

D:\Java>javac Testing\src\scannerTesting\ScannerTesting.java

D:\Java>java Testing\src\scannerTesting\ScannerTesting Exception in thread "main" java.lang.NoClassDefFoundError: Testing\src\scannerTesting\ScannerTesting <wrong name: scannerTesting/ScannerTesting> . . .

1

2 Answers 2

3
java -cp ./Testing/src scannerTesting.ScannerTesting 

When you run java, it looks for matching classes within its classpath. So what these arguments are doing is add your source folder to the classpath using -cp, and specify that the class that should be run is scannerTesting.ScannerTesting.

For more information, check out java cli tool documentation at Oracle

Sign up to request clarification or add additional context in comments.

6 Comments

It worked when i went to root. Can you explain the logic behind that?
I'm kind of new to executing files from command prompt, so I would like an explanation to how the above works.
I also have a file which needs to be read. Which directory should that be in? Currently it's in the Testing folder but it isn't working. However it executes fine when I'm using eclipse
Where you run the command matters. You should be in the Testing folder when you execute it, then you could specify -cp as just src. This will set the correct classpath and have the working directory as Testing
Is there a difference between \ and /?
|
0

scannerTesting is your package name,right?

If so, I suggest you run command "java" under the workspace D:\Java\Testing\src

java scannerTesting.ScannerTest 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.