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.)
Related
I used the command brew install openjdk#11 to install Java on my mac. But when I run
java --version, I get the following message:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
I have a few questions:
How do I install JRE using HomeBrew?
Which JRE version do I need to install?
The answer to your question can be found by running:
brew info openjdk#11
Part of the output is:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk#11 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk#11 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
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!
I tried to install netbeans 'netbeans-7.2.1-ml-linux.sh' on my ubuntu12.04
But when i am executing this .sh file i am gettig the exception given below.
Configuring the installer...
Searching for JVM on the system...
Extracting installation data...
Running the installer wizard...
Can`t initialize UI
Running in headless mode
Exception: java.awt.HeadlessException thrown from the UncaughtExceptionHandler in thread "main"
You need to install Java Runtime Environment
sudo aptitude install default-jre
Refer to this answer:
netbeans installation error: can't initialize ui running in headless mode
Worked for me. For some reason, with OpenJDK the installer was unable to open a GUI.
The Problem is the support of openJDK for the UI.
The solution is installing Oracle JDK, open your terminal and write the following commands:
sudo apt-get remove openjdk*
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java7-set-default
after that reinstall netbeans.
You're missing a X-Server for installation (java.awt.HeadlessException). The installation script needs a UI.
For some reason the sh installer does not work with the openJDK 7.
Quick fix to install is to change back to JDK 6.
run:
sudo update-alternatives --config java
(select java 6)
sh netbeans-7.2.1-ml-linux.sh
the installer should run and then just switch back to the java 7 JDK with update-alternatives.
In my case, I had openjdk installed, where /usr/bin/java was point to the installed openjdk.
I solved it by installing the Oracle JDK 7, from a tar.gz file. Extract the tar ball to a location say your $HOME directory.
After that
I modified the .bashrc file and modified the PATH variable to
PATH=$HOME/jdk1.7/bin/:$PATH export PATH
Remember the path to your jdk/bin should be appended to PATH, as as result the system will find the java executable in your path rather than picking the installed openjdk.
Note: I chose not to uninstall installed openjdk, as most of my Libreoffice and other installed applications were depending on it.
First you have to update
sudo apt-get update
Then default java
sudo apt-get install -f default-jre
sudo apt-get install -f default-jdk
And should be done.
This is what fixed it for me:
I installed the Java JDK. In this case:
sudo aptitude install openjdk-8-jdk
Here's the kicker: I made sure that my Home and Path variables were set properly. Again, in my case:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
My initial issue was not having the JDK installed. It was then not having the environment variables properly set. If they aren't properly set, the installer won't launch. Simple as that.
I'm trying to install Jetty on Ubuntu 11.04 and I'm about to pull my hair out. I'm running into a classpath issue. I start Jetty with start.jar, setting JAVA_HOME to point to the JDK.
/usr/share/jetty$ export JAVA_HOME=/usr/lib/jvm/java-6-sun
/usr/share/jetty$ java -jar start.jar
[...]
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-sun-1.6.0.26/jre"
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:127)
...
Notice that it's ignoring the JAVA_HOME I set, and using the jre. I've also tried this:
java -classpath /usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar
Same error message. It's not finding, com.sun.tools.javac.Main, and that's in tools.jar.
Down in the guts of Jetty, when it's trying to compile my .jsp's, it's using Ant, and that's doing some kind of classloader tricks, I'm guessing. Does anyone know what the secret is to telling this cranky software where my tools.jar file can be found??
Note that I've gotten the same error with the sun jdk and openjdk and, yes, I do have the JDK installed, not just the JRE.
The way apt-get installs java, the java binary that's part of the JDK points into the JRE. Like this:
ls -alph /usr/lib/jvm/java-6-sun/bin/java
lrwxrwxrwx 1 root root 15 2011-10-25 18:48 /usr/lib/jvm/java-6-sun/bin/java -> ../jre/bin/java
I'm guessing that Jetty, Jasper or Ant does some trickery to try and find tools.jar based on the location of the java executable, and that's what's failing here.
Any clues are greatly appreciated. Thanks!
Though you're exporting a new JAVA_HOME environment variable, I don't see that you're also exporting a new PATH environment variable. You're probably still picking up the java executable from the original Java home location. Try including export PATH=$JAVA_HOME/bin:$PATH.
Since comments are kinda unreadable on SO, here's the info you asked for:
$ lsb_release -s -c
natty
I installed the sun JDK like so, but remember that the same error occurred with openjdk.
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get -y install sun-java6-jdk
sudo update-alternatives --config java
I'm pretty sure configuring the environment that I run start.jar in is on the wrong track, since I tried pretty hard with that and got nowhere.
Jetty call's Jasper, which calls the Ant task that compiles your JSPs. In the source for Ant's org/apache/tools/ant/taskdefs/Javac.java you can see where it's setting the classpath.
My problem likely has something to do with passing or not passing environment variables or maybe java systems properties down that chain.
An Ugly Solution
Just for laughs, I created a symbolic link from /usr/lib/jvm/java-6-sun/lib/tools.jar to /usr/lib/jvm/java-6-sun/jre/lib/ext. Ugly, huh? But, it works.
You can add tools.jar to the boot classpath of the JVM:
java -Xbootclasspath/p:/usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar
I have been following this tutorial, and at step 5, I am getting the following output from GCC:
HelloWorld.c:1:17: error: jni.h: No such file or directory
In file included from HelloWorld.c:3:
HelloWorld.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
HelloWorld.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
I know that he include directories vary from system to system, so I tried to adapt the command accordingly, but I cannot seem to find the correct directory on my system. I am using Ubuntu 10.04LTS.
Open up a terminal and type:
locate jni.h
That should tell you where every file called jni.h is on your system. I am on ubuntu 11.04, and it's located at:
/usr/lib/jvm/java-6-openjdk/include/jni.h
/usr/lib/jvm/java-6-sun-1.6.0.26/include/jni.h
You may also need to get it from the repos:
sudo apt-get install openjdk-6-jdk
should do the trick if you don't have it installed.
jni.h lives with JDK. For me it is: jdk1.6.0_25/include/.
And by default, I don't think Ubuntu would have JDK with development libraries, so download latest JDK version from Oracle and install it somewhere.
Or you can install openjdk as #Leif suggested if it works on 10.04 LTS. Although, I personally, prefer the one from Sun/Oracle.
In Ubuntu 14.04 run:
sudo apt-get install openjdk-7-jdk openjdk-7-jre-lib
Now, you have a headers into /usr/lib/jvm/java-7-openjdk-amd64/include
For OpenJDK 6:
sudo apt-get install openjdk-6-jdk openjdk-6-jre-lib