Java : version verification error in MAC OSX terminal - java

i'm new to mac. and i installed the netbeans IDE . so i just went to verify it in the terminal. then i'm getting an error while finding out the version ?this is the screenshot of the terminal.

From the NetBeans IDE, you can select the 'Tools' menu drop-down at the top of the screen. This has an option, 'Java Platforms'. Clicking on this will bring up a window that shows details of the Java platforms you have configured. For each platform the Platform Folder is displayed, which will include the version information in the directory name.

You should write to terminal like this
java -version

Related

Cannot compile java program on linux machine

I'm trying to write a Java program in Intellij on Ubuntu 18.04. There is nothing wrong with the code, I can run it on my Windows machine at home.
When I'm trying to build the program i get the following error message:
Error:Cannot run program "/usr/bin/jdk1.8.0_202/bin/java" (in
directory "/home/oskar/.IdeaIC2019.1/system/compile-server"): error=2,
No such file or directory
First of check that /usr/bin/jdk1.8.0_202/bin/java is present - as in check that you have the Java SDK.
If you have it, Then you need to specify the SDK for your projectin iteliJ. To do this goto Project setting and select your SDK with the drop down, as shown below
Goto File -> Settings -> Project and you will see the bellow menu.
If you don't have the Java SDK there, go ahead and install the Java JDK download from https://www.oracle.com/technetwork/java/javase/downloads/index.html After installing the SDK, navigated to the Project Settings again and select the new JDK configuration from the installation location.
Then you can build the project and it should work all fine!

Can't install Eclipse - "Failed to create the Java Virtual Machine" on Mac

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.

Can't download JDK 8

I'm trying to setup Unity to build for Android. But I can't get the Java Development Kit. Can't download it and can't find it either.
In this answer, the guy says
To ensure JDK is installed, just go through the following :
press Win + R
type 'cmd' in the popup and press button OK.
in the console which has opened, type javac -version and press enter.
You should see as an output :
javac 1.8.0_XX
If so SDK is installed.
I did that and I got "javac 1.8.0_XX", and so I assumed I had the JDK, so I went to Unity > External Tools > JDK and tried linking the following path: "C:\Program Files\Java\jre1.8.0", and got the error message: "The path you specified does not look like a valid JDK installation. Android development requires at least JDK(1.7), having JRE only is not enough. Please make sure you are selecting a suitable JDK home directory or download and install the latest JDK: link"
I clicked the download link for windows x64 and it never loads and eventually says there's no connection. I tried the x86 as well.
In this SO question How do I find where JDK is installed on my windows machine?
Answer: For windows, in the command prompt:
c:\> for %i in (java.exe) do #echo. %~$PATH:i
And so I did that and got the path "C:\ProgramData\Oracle\Java\javapath\java.exe"
When I try linking via Unity > External tools > JDK it doesn't find any files.
I'm a bit clueless now.
#RealAnyOne, you have installed Java with JRE only installation i.e., without out a JDK that’s what you see only one folder and this is why it also showing version in the command line since it won’t check for JDK. JRE is Java Runtime Environment, JDK is Java Development Kit which contains many essential libraries. So Ideally there should be two folders JRE and JDK. This is the reason you are getting this issue with Unity.
To Fix::
Uninstall old Java 8
Download Java 8 from the oracle website
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Install it. Now you should have two folders. Then point your Unity to it.

I can't get Eclipse Luna to run on my mac

I have a mac running os x 10.9.4 and I downloaded the newest version of eclipse. It downloaded fine and installed but whenever I try to open it, I get an error that says, "Version 1.6.0_65 of the JVM is not suitable for this product." I downloaded and installed Java 7 and tried opening eclipse again only to get the same error. Anybody know how to fix this? Thanks
Make sure you have the JDK installed. Google will point you to the runtime engine (JRE) if you search for a Java download (probably called jre-7u67-macosx-x64). Click on "show all Java downloads" in the download page and look for a link "looking for the JDK?" on the left . As of today, the JDK can be found here and should have a name like jdk-7u67-macosx-x64 or jdk-8u20-macosx-x64. Both should be fine for a recent Eclipse Luna install.
If you want to run Eclipse Luna with Java 1.6, you can change the entry in the .ini file. Open the Eclipse application bundle by control-clicking and select "show contents". You will open a new finder window with a single folder "Contents". Open it, then open the folder "MacOS" and edit the file eclipse.ini which you will find inside. Change the line -Dosgi.requiredJavaVersion=1.7 to -Dosgi.requiredJavaVersion=1.6. Close and save, and now Eclipse will run in a minimum configuration. But you really want to install the 1.7 JDK.
For those using Mac OS X Mountain Lion (10.8)+. When you launch Eclipse for the first time, you may see the message "Eclipse can't be opened because it is from an unidentified developer."
To launch Eclipse for the first time, press the control key, click on the Eclipse icon, and select Open.

How can I launch eclipse mavericks from the doc

I'm trying to install eclipse on maverick. I've installed Oracle java 1.7 and can launch eclipse using the link I found in the untared eclipse directory. However, when I pin the icon to the mac dock, trying to open eclipse using that icon results in 'Software Update' telling me 'To open "Eclipse," you need a java SE 6 runtime. Would you like to install one now?'
I guess that this method of launching is somehow not using the eclipse.ini file in which I have used the -vm option to specify that eclipse be launched using the oracle 1.7 version of java on my system.
Anyone know how I can fix this? I wondered if I can edit a config file for the doc entry similar to the way I can add items to ubuntu's launcher perhaps?
I was able to fix this by running Apple's Mavericks Java fix. Even though the fix claims to install Java 6 it ended up just reconfiguring my already installed Java 7 and Eclipse is now able to run normally from the dock and command line. My default JVM is still java 7.
http://support.apple.com/kb/DL1572?viewlocale=en_US
Do you have the latest version of 1.7?
Oracle's Java version 7u25 and below have been disabled by Apple on OS X.
https://www.java.com/en/download/faq/java_mac.xml
Ah,your question solves me . After I update my MAC OS X to mavericks,I can not open my eclipse .I use "open Eclipse.app" or click eclipse on dock .It doesn't work .says"your need java se 6 runtime"
Then I follow your advice ,run "Eclipse.app/Contents/MacOS/eclipse",greet! I open it.
It seems this is the only way to run eclipse on mavericks~
I have a sneaky suspicion that I have a fix for this, but as my system has 1.6 in already I can't test it at the moment.
In the eclipse.ini file you will find the following vm arg; -Dosgi.requiredJavaVersion=1.6 I have a suspicion that if you changed this line to
-Dosgi.requiredJavaVersion=1.7
you might find that you could launch eclipse without the need for java 6. OSGi is the technology that Eclipse uses to manage and run its plugins.
The location of eclipse.ini is dependent on the system but on a Mac you can find it in /Eclipse.app/Contents/MacOS/eclipse.in.

Categories

Resources