0

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:

  • JAVA_HOME = C:\Program Files\Java\jdk1.8.0_05
  • JUNIT_HOME = C:\JUNIT
  • CLASSPATH = %CLASSPATH%;.;%JUNIT_HOME%\junit-4.11.jar;%JUNIT_HOME%\hamcrest-core-1.3.jar;
  • Path = other stuff...; C:\Program Files\Java\jdk.1.8.0_05\bin

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?

Akshay
  • 814
  • 6
  • 19

2 Answers2

1

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?

Community
  • 1
  • 1
Akshay
  • 814
  • 6
  • 19
0

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'

niekname
  • 2,528
  • 1
  • 13
  • 27