I'm trying to set up a java project to use openjdk-11 and all the answers I have found so far have me going in circles. I'm using ubuntu 20.04, so I used the command 'sudo apt install openjdk-11-jre'. The installation seemed to be successful but now I can't seem to figure out the file path to the installed JRE. I thought it would be under /user/lib/jvm/java-11-openjdk-amd64 somewhere. When I point eclipse to that location and try to search for a JRE however it doesn't find anything.
I have found lots of examples with info on how to install but nothing about how to track down the exact file path. Any help would be greatly appreciated.
Update
While I was able to find the JRE location, the root problem turns out to be eclipse. I forgot I had an older version (4.6) open since that is what the project was originally using. Once I switched over to 4.18 I was able to add the java 11 JRE.
Using which will give you /usr/bin/java which won't help as it will be a symlink. You need something like
readlink -f $(which java)
you can use the following:
update-alternatives --list java
will gives you something similar to the below:
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
I'm trying to build a maven project but keep getting error:
Fatal error compiling: invalid target release 16
If I look at my java version
java -version
I can see it is the wrong one:
openjdk version "11.0.11"
even though my path env var is set correctly to c:\Program Files\Java\jdk1.8.0_291\bin
If I do
mvn -version
then it returns the correct one:
Java version: 1.8.0_291
I have opened a new command shell. Same result.
I have rebooted the machine, same result. I have deleted recursively the folders that contained those wrong versions. Same result.
Now I do "where java" and it shows 3 locations remain. 2 are correct but the 3rd shows the culprit:
c:\program files\jetbrains\intellij idea community edition 2021.1.2\jbr\bin.
java -version in there shows "openjdk version "11.0.11 2021-04-20"
why is intellij java overriding my java?
Any ideas?
Depends on your system and your configuration.
Maven and other tools don't care about your PATH. They use the system java registry service to figure out which java they prefer. What does this service look like? Depends on your OS. On windows its registry keys. On mac it's /usr/bin/java which is a softlink that redirects to other stuff. Even if they don't, they'll look at JAVA_HOME (the environment variable) and use that. They don't use the PATH.
Just because some java dir is on your path doesn't mean anything if a java executable is in some earlier PATH. Note on e.g. mac and many linux distros, /usr/bin/java is a thing, and /usr/bin is usually at the start of your PATH variable. This is a java that redirects to the real java. On ubuntu you'd configure this with java-alternatives, etcetera.
If running in an IDE, the IDE doesn't care about any of this and has its own configuration.
The exact explanation of what to do depends on a combinatorial explosion of your JDK installation(s), your OS (and not just 'linux', the specific distro), and the tool you use, that listing it all is a fool's errand.
Make sure the module and project JDK is set to 16 JDK:
I'm trying to install Eclipse, but I can't get the installer to start. It fails with
"Failed to create the Java Virtual Machine"
How can I resolve this?
Note: I'm on Mac.
Edit the file /Applications/Eclipse.app/Contents/Info.plist
There is a comment for use a particular JVM:
<key>Eclipse</key>
<array>
<!-- to use a specific Java version (instead of the platform's default) uncomment one of the following options,
or add a VM found via $/usr/libexec/java_home -V -->
<string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk8u192-b12/Contents/Home/jre/</string>
<string>-keyring</string>
<string>~/.eclipse_keyring</string>
</array>
It took me some time to figure this out as well. The main takeaway was eclipse does not support SDK Version 14 (as of eclipse 2020-03). That was not completely obvious to me.
Install a supported version (I used Homebrew to install SDK V8 🍺):
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
If this is the only Java Version you have installed you should be fine and Eclipse should open up. If that is not the case and you have another Java Version installed. You have to tell Eclipse which Version of Java it should be using (see Step 2).
Tell Eclipse which Version to use by editing the /Applications/Eclipse.app/Contents/Info.plist file as described by Juan Ignacio Barisich and Brad Parks. That being the version you installed in step 1.
nano /Applications/Eclipse.app/Contents/Info.plist
# or
open /Applications/Eclipse.app/Contents/Info.plist
<key>Eclipse</key>
<array>
<string>-keyring</string>
<string>~/.eclipse_keyring</string>
<string>-vm</string>
<string>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/</string>
</array>
Disclaimer: Please bare in mind that those were the steps I took to get eclipse running again. Because I'm nowhere qualified to give a precise answer about this please take a look at the comments in case I got something wrong.
Edit: See Christian Fries answer who pointed out that all java versions 8 to 13 are supported by eclipse.
For me, I had to edit the eclipse-inst.ini file located here:
Eclipse Installer.app/Contents/Eclipse/eclipse-inst.ini
and add the path to my local java VM at the very top of the .ini file, which is here:
-vm
/Users/bparks/jdk/jdk1.8.0_162_x64/bin/java
If the Eclipse Installer.app file is in a DMG, right click on it, and copy it, then paste it into another folder. Then right click on that app file, and choose "Show Package Contents", to get into the files inside the application.
If you've already got Eclipse installed, and find it's throwing the same error, you could try a similar approach by editing the following file for Eclipse:
/Applications/Eclipse.app/Contents/Eclipse/eclipse.ini
On mac, you can get the full path you'd need to your java exe by running the following in a terminal, which will copy the path to your clipboard.
$ echo $(/usr/libexec/java_home)/bin/java | pbcopy
Note: The error "Failed to create the Java Virtual Machine" also exists with Eclipse 2020-03 (under some situations, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=561273) and it is not required to use Java 8 (with Eclipse 2020-03).
For the impatient:
You can run Eclipse or the Eclipse Installer with a given VM without changing eclipse.ini by starting it via a command line:
Open Terminal an run:
open PATHTOECLIPSEINSTALLER/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin
where PATHTOECLIPSEINSTALLER is the path of the folder where Eclipse Installer is located and NAMEOFJDK is the name of the folder with the JDK (11, 12, 13).
For example:
open Downloads/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin
In the installer you may select the VM used by Eclipse. Use a compatible VM here and the installer will modify the eclipse.ini for you.
Explanation TL;DR
To clarify this issue:
Eclipse - say Eclipse 2020-03 - runs with Java 11, Java 12, Java 13, but does not run with Java 14. It fails with the message "Failed to create the Java Virtual Machine". This happens for the installer and for Eclipse itself.
You can download Eclipse without the installer from here: https://www.eclipse.org/downloads/packages/
Explanation:
On macOS, if you start a freshly installed Eclipse, it will use the default JVM. The default JVM is obtained by running /usr/libexec/java_home.
This program /usr/libexec/java_home will find the installed JDK with the highest version as default. That is, if you have JDK 14 installed and run Eclipse 2020-03, you will see this error.
Solution
Summarising some other answers here, there are three options:
Once you have removed JDK 14 from /Library/Java/JavaVirtualMachines/ the error will be gone.
If you like to have JDK 14 installed, start the installer with a different JDK via the command line open Path-to-Eclipse-Installer/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin
You may edit the eclipse.ini (as suggested in other answers) to use a specific JVM.
Referring to Marseille Joseph
https://www.eclipse.org/forums/index.php?t=msg&th=1102885&goto=1823113&#msg_num_13
This worked for me!
Their solution didn't require uninstalling jdk14 or to editing the eclipse.ini file. Instead, do this:
cd /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/MacOS/
sudo rm /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/MacOS/libjli.dylib
sudo ln -s /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home/lib/libjli.dylib libjli.dylib
I started facing the same problem in mac suddenly after updating to macOS Monterey, So I just did the following steps:
Then go to Contents/Eclipse/eclipse.ini file and open it with any text editor and you will see the following:
Add below line before -vmargs as shown in above image:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java
This below line will be different for all the users:
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/java
and you can just get this line copied to your clipboard using this command in terminal:
$ echo $(/usr/libexec/java_home)/bin/java | pbcopy
Similarly will be for STS:
Then go to Contents/Eclipse/SpringToolSuite4.ini as shown below and open with any text editor app.
You will see the following:
Just add the same line that you added for Eclipse in the above steps:
delete all java folder inside /Library/Java
then install a new jdk from
https://adoptopenjdk.net/
which will install at
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk
then try reinstalling eclipse a
I had the same problem in my mac. Here is my solution.
First: I've uninstall all the versions of jdk, because I've try a lot of options.
To do this, you need to go to Library/Java/JavaVirtualMachines
and delete all the folders.
Second: Install jdk 1.8 here is a link to download this version:
jdk 1.8
Third: Install eclipse 2020-03 and thats all.
If you want to use JDK 14, you need to follow this steps:
Open eclipse
Go to Help > Install new software
In the Install window copy the following link in Work with https://download.eclipse.org/eclipse/updates/4.15-P-builds/
Select the third option show in the picture below
Then, click "next" and finish the install
Now you have to change the options, go to Preferences (command + ,) > Java > Compiler and search the version 14. Before this step you need to install jdk 14 (link) Perhaps eclipse would suggest you to change to the correct JREs, for this you need to go to Java > Installed JREs and add the correct version. When you click add you need to choose he JRE type, in my case I use a MacOS X VM and Standard VM, then you have to choose the directory (/Library/Java/JavaVirtualMachine/jdk-14/Contents/Home and click open you could give a JRE Name and finish eclipse will be restart and now you can use eclipse with java 14.
This works for me, I hope you have understood me.
Go to /Library/Java/JavaVirtualMachines
Delete all version except one in use.
Install jdk 8 from brew work for me. You can get the instruction on installing Jdk 8 from HomeBrew here How to install Java 8 on Mac
I met this problem with eclipse-java-2020-03-M2-macosx-cocoa-x86_64, and opendjdk11. The latest eclipse installer at the moment also complained same error.
After I switched back to openjdk8, everything goes well...
For Windows OS:
open eclipse.ini in the Eclipse program folder
add the below lines at the top of the file
-vm
path-to-java-bin\javaw.exe (for example: C:\Program Files\Java\jdk-11.0.10\bin\javaw.exe)
I mounted eclipse dmg file and copied eclipse inside Applications. Then I tried to modify file Info.plist located inside Contents as below, but was getting that this file Info.plist is readonly error. I noticed that I already have read and write permission but still it was giving me that read only error. Then I moved the contents of Eclipse to some other local folder and then edited Info.plist, it did not give me readonly error.
<array>
<string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java</string>
<string>-keyring</string>
<string>~/.eclipse_keyring</string>
</array>
Finally I am able to open eclipse.
I'm trying to make a cross-platform JavaFX application, and it works fine on Windows and OSX machines, but not on Linux.
When I try to run it on a Linux machine using java -jar app.jar, this is what I get:
Error: Could not find or load main class app.Main
But the class app.Main is in the .jar, as shown by 'jar tf app.jar':
...
app/Main.class
...
I tried specifying the main class using java -cp app.jar app.Main but I got the same error message.
The .jar was built in Intellij IDEA, using basic JavaFX configuration.
Any help?
So, turns out the problem was that the JRE on the Linux machine was OpenJDK, which does not come with JavaFX, as noted by James_D and jewelsea
After installing the oracle JRE 8, it worked fine
Sorry for the necro post, but I had to take a few extra steps. I had JRE 8 installed, but I still had to point java_home to it.
I'm using a MAC.
The JDK locations are here:
/Library/Java/JavaVirtualMachines (verify this)
The default JDK for my machine was temurin-17.jdk
I had to change it to jdk1.8.0_301.jdk
Steps:
Open a terminal
Type:
vim ~/.bash_profile
I pasted this onto the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
Save and exit vim:
https://phoenixnap.com/kb/how-to-vim-save-quit-exit
In the terminal, type:
source ~/.bash_profile
Restart your terminal
In the terminal, type:
java -version
Make sure it's pointing to the right version
Now navigate back to where the .jar is located.
In the terminal, type:
java -jar myapp.jar
Hope this helps.
I'm trying to run IntelliJ on Ubuntu 14.04. I've read this question but the solutions don't apply -- I've definitely got the JDK installed rather than the JRE. When I try to run idea.sh, I get the error message:
'tools.jar' seems to be not in IDEA classpath. Please ensure JAVA_HOME
points to JDK rather than JRE.
JAVA_HOME is set to /etc/java-7-openjdk. Eclipse (in the form of Eclim) has no problem finding it. javac -version prints javac 1.7.0_55.
However, if I run sudo ./idea.sh, IntellJ launches fine. What am I missing?
I had the exact same problem half an hour ago. Took me exactly that half hour to fix it, this is how it worked for me:
Short version:
add
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
to your .bashrc, source it and you are fine.
Explanation:
After installing the JDK in Ubuntu there are multiple folders on your disk.
The root folder is
/usr/lib/jvm/java-7-openjdk-amd64/
under which the aforementioned /jre -Folder resides.
The whole problem is, that the jre/lib -Folder does not contain the tools.jar - File searched by the IDE.
Only the /usr/lib/jvm/java-7-openjdk-amd64/lib - Folder does.
To get everything working you have to specify /usr/lib/jvm/java-7-openjdk-amd64 as JAVA_HOME.
Setting /usr as your JAVA_HOME wont solve the problem as that is symlinked to /etc/alternatives which is symlinked to our old friend the /jre-Folder.
I hope this helped you!
In the 64 bit Debian 7, I solved the problem by adding this two lines of code in idea.sh under the /path/to/intellij-folder/bin/
export IDEA_JDK=/path/to/jdk/
export JAVA_HOME=/path/to/jre
And I hope it will solve the problem in Ubuntu.
It turns out JAVA_HOME was set wrong, I needed to set it to:
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
to get it working. I'm not sure why this hadn't caused me any problems before.
EDIT: This setting makes Maven angry (although Maven via IntelliJ works fine). For future readers, I believe the correct setting is:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/
you can change your current java version as follows
alternatives --config java
alternatives --config javac
but before them you need to install your newly installed JDK in alternatives properly:
alternatives --install /usr/bin/java java [new-jdk-path]/bin/java 120 --slave /usr/bin/rmiregistry rmiregistery [new-jdk-path]/bin/rmiregistry --slave /usr/bin/keytool keytool [new-jdk-path]/bin/keytool --slave /usr/lib/tools.jar tools.jar [new-jdk-path]/lib/tools.jar
alternatives --install /usr/bin/javac javac [new-jdk-path]/bin/javac 120 --slave /usr/bin/jar jar [new-jdk-path]/bin/jar --slave /usr/bin/rmic rmic [new-jdk-path]/bin/rmic