2
votes

Not sure what the issue is here but javac is not recognized when I try to compile a java file. I am assuming I need a special plugin for this or I am required to use apache ANT but not too sure.

cd src

javac HelloWorld.java

'javac' is not recognized as an internal or external command,
operable program or batch file.

java HelloWorld

Error: Could not find or load main class HelloWorld
3
javac (the Java Compiler) is not found in the PATH. Is an appropriate Java JDK (not JRE) installed? - user2864740
You need to add bin folder of JDK to PATH (for the Jenkins user). - eis

3 Answers

5
votes

In Jenkins goto Manage Jenkins -> Configure System , scroll down to JDK installations and click the ADD JDK button.

I recommend trying the Install Automatically option, and let it install a fresh copy and give it a name you can recognize in project setting like jdk8_update51, and agree to the license.

In each project check that the JDK Setting is the correct version.

In windows batch command text box, you may want to add

echo "PATH is:" echo %PATH%

echo "JAVA_HOME is:" echo %JAVA_HOME%

javac -version

If this fails as above, try :

eg.

set PATH="C:\Program Files\Java\jdk1.8.0_31\bin"

javac -version

should print the following in Console Output:

javac 1.8.0_31

Note: "C:\Program Files\Java\jdk1.8.0_31\bin" should have the file javac.exe in it.

0
votes

For Resolving this issue Go to :

Jenkins --> Manage Jenkins --> Global tool configuration.

You can add the full path JAVA_HOME there or click on "install automatically" for automatically downloading the Java.

I just tried this and issue is resolved now.

Thanks to Stackoverflow as well !!

0
votes
  • Select "Manage Jenkins" and then "Configure System" on the Dashboard.

java jdk configuration

  • On the screen that opens, there is the "Environment variables" section. The tick next to it is marked. Then click the "Add" button. The «name» and «path» fields that appear after this marking are filled by entering the java-jdk path as in the image. Then click "Apply" and "Save" to complete the process.
  • That's all. I hope this will fix your problem. :)

**This solution can use for all similar command errors for python,maven, etc. **