Kasey Champion
Kasey Champion

Reputation: 1

Error when Compiling JUnit from Command Line

I am trying to implement my own junit test runner in windows command line and my installation is all messed up. Here are my environment variables:

When I run "javac TestRunner.java" in the proper directory I consistently get the errors " 'javac' is not recognized as an internal or external command "

So instead I run "C:\Program Files\Java\jdk1.8.0_05\bin\javac" TestRunner.java which compiles fine

Then I try to run "java TestRunner.java" and I get the error "Error: Could not find or load main class TestRunner.java" but that class runs fine when I run it from within an editor.

Help! What's going wrong?

Upvotes: 0

Views: 740

Answers (2)

niekname
niekname

Reputation: 2626

Your JAVA_HOME var has "jdk1.8.0_05" Your Path var has "jdk**.**1.8.0_05"

Could be just a typo here of course.

I suggest you adjust your Path var to -> %JAVA_HOME%\bin

If your variables are set correct, you should be able to execute 'java -version' in command prompt from within any folder

Your other problem for running your program should be solved by running is as 'java TestRunner', not 'java TestRunner.java'

Upvotes: 0

Akshay
Akshay

Reputation: 812

I think you want

java TestRunner

not

java TestRunner.java

The java command is for running compiled Java code, but you're giving it a source file which is confusing it. Read this if you're still confused: What does "Could not find or load main class" mean?

Upvotes: 1

Related Questions