Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate the Javac Compiler

I tried to mvn install and got this message:

Compilation failure
Unable to locate the Javac Compiler in:
  /usr/lib/jvm/java-7-openjdk-amd64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

Well, there is an open jdk, I also downloaded another one. I tried to point JAVA_HOME to both, now it is set:

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_03
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

I also tried to choose one of those open with sudo update-alternatives --config java but got the same error with different jdk versions in it.

How can I fix that? Thanks in advance.

like image 758
John Doe Avatar asked May 30 '12 08:05

John Doe


People also ask

Where is Javac compiler located?

The value that you want to add is most likely C:\Program Files\Java\jdk-14.0. 2\bin if you are installing "JDK 14.0. 2". This is the location where the Java compiler ('java.exe') was installed in your file system.

How do I open Javac exe?

Hi, Welcome to JavaRanch! "javac.exe" is a command-line program. You have to run it by typing "javac" at a command prompt -- i.e., the "MS-DOS Window".


2 Answers

it seems like your PATH is not picked up correctly... does the output of "echo $PATH" contain the directory where javac resides? I would suggest following:

open terminal and do an:

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_03
export PATH=$PATH:$JAVA_HOME/bin
javac -version
which javac

if javac -version still does not work create a symlink in /usr/local/bin pointing to your javac binary:

cd /usr/local/bin
ln -s /usr/lib/jvm/jdk1.7.0_03/bin/javac javac

this should get you up an running... an alternative is to try setting up java via your package management system (e.g. "apt-get install java" or sth. similar)

like image 83
Korgen Avatar answered Sep 30 '22 01:09

Korgen


I faced similar error on an ubuntu machine while running a maven build from Jenkins. If output of 'javac -version' prompts below messages:

"The program 'javac' can be found in the following packages: default-jdk ecj gcj-5-jdk openjdk-8-jdk-headless gcj-4.8-jdk gcj-4.9-jdk openjdk-9-jdk-headless Try: apt install "

Then you can install "openjdk-8-jdk-headless" using:

apt install openjdk-8-jdk-headless

This solved my problem and the maven build went through ok.

like image 37
Yeamin Rajeev Avatar answered Sep 30 '22 02:09

Yeamin Rajeev