I had the following command working fine with OpenJDK
mvn clean install
I then uninstalled OpenJDK and installed Oracle JDK 8, and now when I run mvn clean install
The JAVA_HOME environment variable is not defined correctly This
environment variable is needed to run this program NB: JAVA_HOME
should point to a JDK not a JRE
I'm running Linux Mint 19, I did run into a few Stackoverflow questions related to the issue. Most where related to Windows and some that were related to Linux. The Linux ones recommended to run
sudo update-alternatives --config java
but in my case I get
There is only one alternative in link group java (providing
/usr/bin/java): /usr/lib/jvm/java-8-oracle/jre/bin/java Nothing to
configure.
Any idea how I can make mvn clean install work again?
May be java path configuration missing. You can follow this steps:
Create or export JAVA_HOME="JDK directory" . Ex. "C:\Program Files\Java\jdk1.8.0_65"
Create or export Path variable for PATH="JDK Bin DIrectory" . Ex. "C:\Program Files\Java\jdk1.8.0_65\bin"
Run command java -version from your terminal.Check it is correct or not.
Then configure maven. follow these steps :
You can try to install maven globaly. you can skip these steps if already configured.just for check run mvn --version command for checking maven is installed correctly.
Download maven from maven download link
Create or export M2_HOME="MAVEN ROOT LOCATION". Ex. : E:\SoftwareRepo\building tools\apache-maven-3.5.2
Create or export MAVEN bin folder location to PATH variable. For example: E:\SoftwareRepo\building tools\apache-maven-3.5.2\bin
Open terminal or cmd and run mvn --version to confirm maven is installed or not.
You may refer to the link to setup the JAVA_HOME for Linux -
https://docs.oracle.com/cd/E21454_01/html/821-2532/inst_cli_jdk_javahome_t.html
Setting up Maven again :
https://maven.apache.org/install.html
check whether the mvn -v command is working or not..
Then execute other commands with mvn..
Thanks :)
For mac or ubuntu users
Make sure java is installed, if you have installed java 1.7
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 1.7 -f)"' >> ~/.bash_profile
or java 1.8, change the version accordingly.
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 1.8 -f)"' >> ~/.bash_profile
Then
source ~/.bash_profile
Now check,
echo $JAVA_HOME
This should be pointing to correct java version.
I'm doing this for future me's bc after all the links in StackOverflow, the solution was to check mvn.cmd file on C:\Program Files\Maven\apache-maven-3.6.3\bin...
On line 52 it sets the JDK, but it didn't had the "/bin" where my OpenJDK 15 stored the java.exe
This fixed the issue on Windows 11 but it could serve as an idea to check on other OS. Hope that it helps!
Related
I've never worked with Maven before and I am following the instructions here. When I run the command
mvn integration-test -Pamp-to-war
It initially downloaded a whole bunch of dependencies, and in the end it showed,
COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
I am on ubuntu 13.04.
If there's anything you want me to tell you, let me know. Thanks.
EDIT
When I do echo $JAVA_HOME I get /usr/lib/jvm/java-7-openjdk-i386/
When I do mvn -version
I get,
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.0-26-generic", arch: "i386", family: "unix"
Also, I found out this problem faced by someone else. But I am not sure how to go about the solution that is specified?
Further edits.
kraken#kraken-Inspiron-1545:/usr/lib/jvm/java-7-openjdk-i386$ ls -l
total 12
drwxr-xr-x 2 root root 4096 Sep 9 10:44 bin
lrwxrwxrwx 1 root root 41 Jul 4 2013 docs -> ../../../share/doc/openjdk-7-jre- headless
drwxr-xr-x 5 root root 4096 Oct 13 2013 jre
drwxr-xr-x 4 root root 4096 Oct 13 2013 man
I've been facing the same issue with java 8 (ubuntu 16.04), trying to compile using mvn command line.
I verified my $JAVA_HOME, java -version and mvn -version. Everything seems to be okay pointing to /usr/lib/jvm/java-8-openjdk-amd64.
It appears that java-8-openjdk-amd64 is not completly installed by default and only contains the JRE (despite its name "jdk").
Re-installing the JDK did the trick.
sudo apt-get install openjdk-8-jdk
Then some new files and new folders are added to /usr/lib/jvm/java-8-openjdk-amd64 and mvn is able to compile again.
Apparently, it requires tools.jar file inside the lib folder of my $JAVA_HOME. I did not have the lib folder, so I reinstalled my jdk using command
apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib
Also, this link may help some people.
This is because of running jre rather than jdk, to install jdk follow
below steps
Installing java 8 in amazon linux/redhat
--> yum search java | grep openjdk
--> yum install java-1.8.0-openjdk-headless.x86_64
--> yum install java-1.8.0-openjdk-devel.x86_64
--> update-alternatives --config java #pick java 1.8 and press 1
--> update-alternatives --config javac #pick java 1.8 and press 2
Thank You
Problem statement = No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Solution
Please set the Environment variable like below to solve the issue
Variable name : JAVA_HOME
Variable Value : C:\Program Files\Java\jdk1.8.0_202
Variable name : M2_HOME
Variable Value : C:\Program Files\apache-maven-3.6.0
Moreover, Add Java and maven path in "System Variables" like below:
C:\Program Files\Java\jdk1.8.0_202\bin
C:\Program Files\apache-maven-3.6.0\bin
For me, it worked like following.
Please look at JAVA_HOME environment variable, whether it is pointing to JRE or JDK.?
If it pointed to JRE, you will face "Perhaps you are running on a JRE rather than a JDK" issue. if so change the path to JDK.
Modifying like this, it worked for me.
JAVA_HOME C:\Program Files\Java\jdk1.8.0_31
Just adding more details on where to setup. Main reason would be the JAVA_HOME setup in the environment variable should be pointing to correct JDK location.
Check System -> Advance System Settings
Click on Environment variable
Add variable JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_141;"
Edit "path" -> append %JAVA_HOME%; to the existing text.
i am using centos and getting same error when run mvn command with goal, install. After some googling i have found the solution to run following command.
sudo yum install java-1.8.0-openjdk-devel
I get this error when JAVA_HOME is not properly set.
I have tried this command
$ /usr/libexec/java_home -V
which gives 3 virtual machines
Matching Java Virtual Machines (3):
1.8.291.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_291 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
In such case, specific version is required.
This
$ /usr/libexec/java_home -v1.8
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
differs from
$ /usr/libexec/java_home -v1.8.0
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
Therefore solution is to set ~/.bash_profile with
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0`
Add this configurations in pom.xml
<project ...>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Check if /usr/bin has 'javac'. If not you have installed JRE & have to install jdk dev version like "java-1.8.0-openjdk-devel.x86_64"
I was facing the same issue. I needed to place the JDK before the JRE in PATH in order to resolve.
Here's my automatic solution...
This will follow your javac executable's symlink (setup by yum and/or alternatives --config java) backwards to find the JAVA_HOME. (Toss this in your in your /etc/profile):
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')
If you wanted a stable path (refreshed on boot) launch something like this:
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')
ln -sfn "${JAVA_HOME}" /usr/lib/jvm/jdk-current
I'm kinda shocked the latter still isn't baked into alternatives.
This is how i fixed my problem
right clik on the project > properties > Java Compiler (select the one you are using)
it was 1.5 for me but i have 1.8 installed. so i changed it to 1.8.. and voilla it worked!.
I had the same issue after installing the java-1.8.0-openjdk package on an AWS Linux AMI. The incorrect assumption I made, was that because the file ended in openjdk it would be the jdk version. This is not the case.
The openjdk install page explains everything clearly.
The java-1.8.0-openjdk package contains just the Java Runtime
Environment. If you want to develop Java programs then install the
java-1.8.0-openjdk-devel package.
If you've already installed the java-1.8.0-openjdk package, just leave it and the JAVA_HOME value if it's working for the JRE and install the java-1.8.0-openjdk-devel package using yum install java-1.8.0-openjdk-devel -y.
In Installed JREs path see if there is an entry pointing to your JDK path or not.
If not, click on Edit button and put the path you configured your JAVA_HOME environment:
Eclipse Path: Window → Preferences → Java → Installed JREs
Solution for Mac users who recently updated to MacOS Monterey
If you've encountered this issue after updating your macOS to Monterey recently, try running this command:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
Afterwards, continue using maven like usual. Hope this helped :)
I had the same error and I was missing the User variable: JAVA_HOME and the value for the SDK - "C:\Program Files\Java\jdk-9.0.1" in my case
I faced the issue even though JAVA_HOME was pointing to JDK. It took time to figure out why it was throwing the exception.
The issue was I set JAVA_HOME as admin user on my window machine. You need to add JAVA_HOME environment variable pointing to right JDK to your user profile environment variable settings.
For solving my issue on Linux don't have a JDK, I just download the JDK and upload to the Linux server, and type:
tar xvf jdk-8u45-linux-x64.tar.gz
I was facing the same issue in eclipse maven project, all i did was
right click on the project
maven --> update project
or just press ALT+ F5
If the above solutions doesn't work then try to place java path before maven in path of environment variable. It worked for me.
%JAVA_HOME%\bin
C:\Program Files\apache-maven-3.6.1-bin\apache-maven-3.6.1\bin
I was getting below error in Maven project in Eclipse
Error: [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
I solved it by following the below solution
Solution:
Eclipse->Project->Right click->Build Path->Configure Build Path->Add jdk path(Eg:
C:\Program Files\Java\jdk1.8.0_45)
Note: Earlier Build path in eclipse project was pointing to jre path
And also add jdk path in Environment Variable in Advanced system settings
Variable Name: JAVA_HOME
Variable Value: C:\Program Files\Java\jdk1.8.0_45
And also make sure in eclipse below pointing is (jdk path-> C:\Program Files\Java\jdk1.8.0_45 )
Windows -> Preferneces -> Java -> Installed JRE's
Right click on your project folder (Maven one), select properties and from the properties window, again select Java Compiler and see what is selected against compiler compliance level and make sure that it is the same version as your jre. In my case I had 1.8 but 1.5 was selected against compiler compliance level. After selecting 1.8 the build was successful without this error.
too many java virtual machines?
place check with command:
/usr/libexec/java_home -V
java -version
mvn -version
uninstall java click here
I am new to command line and Ubuntu.
I am trying to run this:
mvn clean package -DskipTest
as indicated on this site:
https://github.com/forcedotcom/dataloader/
I opened up Command line and typed.
I am getting error message:
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-oracle/bin/java
Any lead would be appreciated greatly.
Error: JAVA_HOME is not defined correctly.
Show you that JDK isn't installed correctly, you should reinstall JDK, see OpenJDK page, you can try to use following command:
sudo apt-get install openjdk-8-jdk
Have a look here: https://askubuntu.com/questions/175514/how-to-set-java-home-for-java
JAVA_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME
You can also set it in /etc/environment or ~/.profile or ~/.bash_profile etc. But check which version is installed on your system.
Or you download the JDK as tar, unpack it in your home and use that jdk (allwoes to have different versions installed and easy switching those).
I am using Jenkins to build an android project on a mac stadium VM.
When I VNC into the VM, I can build the project just fine. Java is installed at /usr/bin/java, and my $PATH includes /usr/bin.
When I run the same commands from the Jenkins job, it fails with
ERROR: JAVA_HOME is set to an invalid directory: /var/lib/jenkins/jdk1.8.0_25
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
/var/lib/jenkins/jdk... does not exist on the VM. I have also tried updating the build job to include export JAVA_HOME=/usr/bin, but then I get a different error:
Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/bin
All of the other steps seem to work so I can tell that the code is being downloaded to the workspace and everything else is installed properly, and as I said I can build android on the VM from the command line directly.
What can I do to get Jenkins to build on the VM?
The best way to set the JAVA_HOME on a mac is to use java_home after downloading and installing the required JDK from oracle:
export JAVA_HOME=`/usr/libexec/java_home`
If you want Jenkins to use an older version of the JDK ensure use the -v flag:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
To preview the location just type the java_home command into a Terminal:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
I've never worked with Maven before and I am following the instructions here. When I run the command
mvn integration-test -Pamp-to-war
It initially downloaded a whole bunch of dependencies, and in the end it showed,
COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
I am on ubuntu 13.04.
If there's anything you want me to tell you, let me know. Thanks.
EDIT
When I do echo $JAVA_HOME I get /usr/lib/jvm/java-7-openjdk-i386/
When I do mvn -version
I get,
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.0-26-generic", arch: "i386", family: "unix"
Also, I found out this problem faced by someone else. But I am not sure how to go about the solution that is specified?
Further edits.
kraken#kraken-Inspiron-1545:/usr/lib/jvm/java-7-openjdk-i386$ ls -l
total 12
drwxr-xr-x 2 root root 4096 Sep 9 10:44 bin
lrwxrwxrwx 1 root root 41 Jul 4 2013 docs -> ../../../share/doc/openjdk-7-jre- headless
drwxr-xr-x 5 root root 4096 Oct 13 2013 jre
drwxr-xr-x 4 root root 4096 Oct 13 2013 man
I've been facing the same issue with java 8 (ubuntu 16.04), trying to compile using mvn command line.
I verified my $JAVA_HOME, java -version and mvn -version. Everything seems to be okay pointing to /usr/lib/jvm/java-8-openjdk-amd64.
It appears that java-8-openjdk-amd64 is not completly installed by default and only contains the JRE (despite its name "jdk").
Re-installing the JDK did the trick.
sudo apt-get install openjdk-8-jdk
Then some new files and new folders are added to /usr/lib/jvm/java-8-openjdk-amd64 and mvn is able to compile again.
Apparently, it requires tools.jar file inside the lib folder of my $JAVA_HOME. I did not have the lib folder, so I reinstalled my jdk using command
apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib
Also, this link may help some people.
This is because of running jre rather than jdk, to install jdk follow
below steps
Installing java 8 in amazon linux/redhat
--> yum search java | grep openjdk
--> yum install java-1.8.0-openjdk-headless.x86_64
--> yum install java-1.8.0-openjdk-devel.x86_64
--> update-alternatives --config java #pick java 1.8 and press 1
--> update-alternatives --config javac #pick java 1.8 and press 2
Thank You
Problem statement = No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Solution
Please set the Environment variable like below to solve the issue
Variable name : JAVA_HOME
Variable Value : C:\Program Files\Java\jdk1.8.0_202
Variable name : M2_HOME
Variable Value : C:\Program Files\apache-maven-3.6.0
Moreover, Add Java and maven path in "System Variables" like below:
C:\Program Files\Java\jdk1.8.0_202\bin
C:\Program Files\apache-maven-3.6.0\bin
For me, it worked like following.
Please look at JAVA_HOME environment variable, whether it is pointing to JRE or JDK.?
If it pointed to JRE, you will face "Perhaps you are running on a JRE rather than a JDK" issue. if so change the path to JDK.
Modifying like this, it worked for me.
JAVA_HOME C:\Program Files\Java\jdk1.8.0_31
Just adding more details on where to setup. Main reason would be the JAVA_HOME setup in the environment variable should be pointing to correct JDK location.
Check System -> Advance System Settings
Click on Environment variable
Add variable JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_141;"
Edit "path" -> append %JAVA_HOME%; to the existing text.
i am using centos and getting same error when run mvn command with goal, install. After some googling i have found the solution to run following command.
sudo yum install java-1.8.0-openjdk-devel
I get this error when JAVA_HOME is not properly set.
I have tried this command
$ /usr/libexec/java_home -V
which gives 3 virtual machines
Matching Java Virtual Machines (3):
1.8.291.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_291 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
In such case, specific version is required.
This
$ /usr/libexec/java_home -v1.8
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
differs from
$ /usr/libexec/java_home -v1.8.0
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
Therefore solution is to set ~/.bash_profile with
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0`
Add this configurations in pom.xml
<project ...>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Check if /usr/bin has 'javac'. If not you have installed JRE & have to install jdk dev version like "java-1.8.0-openjdk-devel.x86_64"
I was facing the same issue. I needed to place the JDK before the JRE in PATH in order to resolve.
Here's my automatic solution...
This will follow your javac executable's symlink (setup by yum and/or alternatives --config java) backwards to find the JAVA_HOME. (Toss this in your in your /etc/profile):
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')
If you wanted a stable path (refreshed on boot) launch something like this:
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')
ln -sfn "${JAVA_HOME}" /usr/lib/jvm/jdk-current
I'm kinda shocked the latter still isn't baked into alternatives.
This is how i fixed my problem
right clik on the project > properties > Java Compiler (select the one you are using)
it was 1.5 for me but i have 1.8 installed. so i changed it to 1.8.. and voilla it worked!.
I had the same issue after installing the java-1.8.0-openjdk package on an AWS Linux AMI. The incorrect assumption I made, was that because the file ended in openjdk it would be the jdk version. This is not the case.
The openjdk install page explains everything clearly.
The java-1.8.0-openjdk package contains just the Java Runtime
Environment. If you want to develop Java programs then install the
java-1.8.0-openjdk-devel package.
If you've already installed the java-1.8.0-openjdk package, just leave it and the JAVA_HOME value if it's working for the JRE and install the java-1.8.0-openjdk-devel package using yum install java-1.8.0-openjdk-devel -y.
In Installed JREs path see if there is an entry pointing to your JDK path or not.
If not, click on Edit button and put the path you configured your JAVA_HOME environment:
Eclipse Path: Window → Preferences → Java → Installed JREs
Solution for Mac users who recently updated to MacOS Monterey
If you've encountered this issue after updating your macOS to Monterey recently, try running this command:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
Afterwards, continue using maven like usual. Hope this helped :)
I had the same error and I was missing the User variable: JAVA_HOME and the value for the SDK - "C:\Program Files\Java\jdk-9.0.1" in my case
I faced the issue even though JAVA_HOME was pointing to JDK. It took time to figure out why it was throwing the exception.
The issue was I set JAVA_HOME as admin user on my window machine. You need to add JAVA_HOME environment variable pointing to right JDK to your user profile environment variable settings.
For solving my issue on Linux don't have a JDK, I just download the JDK and upload to the Linux server, and type:
tar xvf jdk-8u45-linux-x64.tar.gz
I was facing the same issue in eclipse maven project, all i did was
right click on the project
maven --> update project
or just press ALT+ F5
If the above solutions doesn't work then try to place java path before maven in path of environment variable. It worked for me.
%JAVA_HOME%\bin
C:\Program Files\apache-maven-3.6.1-bin\apache-maven-3.6.1\bin
I was getting below error in Maven project in Eclipse
Error: [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
I solved it by following the below solution
Solution:
Eclipse->Project->Right click->Build Path->Configure Build Path->Add jdk path(Eg:
C:\Program Files\Java\jdk1.8.0_45)
Note: Earlier Build path in eclipse project was pointing to jre path
And also add jdk path in Environment Variable in Advanced system settings
Variable Name: JAVA_HOME
Variable Value: C:\Program Files\Java\jdk1.8.0_45
And also make sure in eclipse below pointing is (jdk path-> C:\Program Files\Java\jdk1.8.0_45 )
Windows -> Preferneces -> Java -> Installed JRE's
Right click on your project folder (Maven one), select properties and from the properties window, again select Java Compiler and see what is selected against compiler compliance level and make sure that it is the same version as your jre. In my case I had 1.8 but 1.5 was selected against compiler compliance level. After selecting 1.8 the build was successful without this error.
too many java virtual machines?
place check with command:
/usr/libexec/java_home -V
java -version
mvn -version
uninstall java click here
I am putting together a dev environment for a Java program and after the first try of my Ant build scripts I got this error:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
While the path to the jdk is correct, the tools.jar really wasn't there. Is it actually supposed to be there or did I get some config/installation thing wrong?
It seems like you can have Java installed in /usr/lib/jvm/java-6-openjdk but only have the JRE, not the JDK. This fixed it for me:
sudo apt-get install openjdk-6-jdk
Note: On CentOS / RHEL installing java-1.x.0-openjdk will not be enough. Also install java-1.x.0-openjdk-devel.
It's there on my machine. I'm running Sun JDK 1.6.0_21 on Windows XP SP3.
Are you sure you have the JDK? Is it possible that you only have the JRE?
On Debian, after installing Ant with apt-get install ant, I've encountered the same error when running it:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk-amd64/lib/tools.jar
Indeed, there's no mention of any tools.jar anywhere in /usr/lib, although /usr/lib/jvm/java-6-openjdk-amd64 itself does exist.
https://packages.debian.org/search?searchon=contents&keywords=java-6-openjdk-amd64%2Flib%2Ftools.jar
As per the search above, java-6-openjdk-amd64/lib/tools.jar appears to be part of openjdk-6-jdk, which indeed didn't get installed with ant (since it's only marked as suggested (https://packages.debian.org/wheezy/ant)).
apt-get install openjdk-6-jdk
apt install defalut-jdk # this doesn't contain some file, like tools.jar...
apt install openjdk-8-jdk # this contains all files.
On Ubuntu I've just need to install JDK
sudo apt-get install openjdk-7-jdk
..and you can always search for all available versions with
$ sudo apt-cache search openjdk | grep ^openjdk
From the website https://openjdk.java.net/install/ we can read
The openjdk-7-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-7-jdk package.
Try the following:
% sudo apt-get install sun-java6-jdk
% sudo update-alternatives --config java
select the option that has the path
/usr/lib/jvm/java-6-sun/jre/bin/java
Worked for me on an ubuntu 10.4
u can try to put your JAVA_HOME also, as follows:
% sudo export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
Installing the jdk-6u45-linux-x64.bin (from the oracle.com site) via unzip does not result in a tools.jar. I guess that file is created by the "make-jpkg" script. Once I did that, and installed the resulting .deb file, everything was fine.
I really hate oracle's lawyers.
Even if you have jdk installed, you'll need to redirect JAVA_HOME to point to it.
Here's one weird trick you can put into your .profile to set JAVA HOME properly, no matter which java you have:
export JAVA_HOME=$(dirname $(dirname $(readlink -e /usr/bin/java)))
# Test for jdk installed above jre
if [ -x $JAVA_HOME/../bin/java ]; then export JAVA_HOME=$(dirname $JAVA_HOME); fi
On Ubuntu I've fixed this problem by installing package
openjdk-7-jre-lib
tools.jar appeared after that.
(I know this is an old post, but comment in hope that it will be helpful for somebody lurking for answer like I was today.)