Eclipse in OS X uses different version of Java than CLI - java

When I type java -version in the console I get java version "1.8.0_05". The soft link /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK points to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents. In the java preferences window, the only listed version of Java is 1.8. JAVA_HOME is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home.
However, when I try to run Eclipse.app, I get the error: Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.7 or greater required.
I believe it is trying to use /System/Library/Java/JavaVirtualMachines and in that directory the only version is 1.6.0.jdk.
How can I get eclipse to use the correct version of Java?

I solved this issue in my mac with yosemite:
Installed JDK for MACOSX 64bits from https://jdk8.java.net/download.html
Inside the eclipse.ini I put this line:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
And it worked for me!

Download the 64-bit version of Eclipse instead of the 32-bit version.
The reason is that Eclipse contains native machine code (for the GUI) which is why there is both a 32-bit and 64-bit version of Eclipse, and this explicitly require the corresponding Java version. Originally Apple created both versions up to Java 6, but Oracle only creates a 64-bit version (much to the dismay of owners of older machines). So, if you download a 32-bit version of Eclipse it will only run with an Apple JVM, which apparently is too old (which surprise me - I thought Java 6 was still supported for Eclipse 4.4)

I faced this same problem but rather than making it to use version 1.8 I changed the settings in eclipse.ini file so I can just run the program regardless which version of jvm does it want to use
Solution:
Open the directory where you have Eclipse copy in your computer.
You would see a file name eclipse press control key and click on it to see the options.
Then click on Show Originalfrom the options, there you would find eclipse.ini file open it with a text editor and change the -Dosgi.requiredJavaVersion=1.7 to -Dosgi.requiredJavaVersion=1.6
Save the file and open the ecplise.app it should open now without any error

Try adding the following lines to your eclipse.ini:
-vm
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
Maybe a newer version of eclipse could help, too (if yours is out of date).

Take a look in your System Preferences -> Java. It should open the Java Control Panel. In the panel, check if you have one (or many) JDKs.
I suspect you have many and are setting the JDK in your .profile while Eclipse is reading some other Java Home.
You can change them manually by running this in your terminal
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
To check if it worked, run java -version and you should see something like
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
Try calling Eclipse now from the command line. To call Eclipse as an App, just set the Java8 through the Java Control Panel. This will be read when Eclipse starts.
This is what I have on my Java Control Panel:
This is on my Eclipse Luna:

Download the 64-bit version of Eclipse.
This solved the problem. Thanks everyone.

Related

Unable to find JAVA icon in System-Preference or Library of my MAC

I have been a Windows user all my life and have recently got a MAC. My Mac is using MacOS Catalina.
I am trying to set-up JDK and get going on a project, however the issue is after I have installed JDK 11.0.4, I don't see any Java-icon on my system preference nor could I find Java folder in my ~library. However, when I go to terminal and do java -version I do see java being present as below
~ % java -version
java version "11.0.6" 2020-01-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.6+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.6+8-LTS, mixed mode)
I need help to see how I can resolved this, and then add my java installed location to my .bash_profile
Normally the JDK is located under
/Library/Java/JavaVirtualMachines.
The AdaptOpenJdk for example is located here: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk
For those of you that are still struggling with it. Here is the thing.
The Java Preferences app was part of Apple Java installation and is not used by Oracle Java. Therefore, OS X releases from Apple that do not include Apple Java will not include Java Preferences.
"What happened to the Java Preferences app in Application -> Utilities?"
Now, after hunting around for a while I have figured the following out:
You won't get JAVA in your Mac's System Preference until you have added JAVA home directory in your bash profile, irrespective of the java version installed
Generally be default Java gets installed in your MacintoshHD
So, open your MacintoshHD & then go to GO option from your Finder
Next click on Go to folder option and type-in ~/Library
Now you will see a Java folder and under that JavaVirtualMachines
You will now have JDK folder of whichever java version installed
Right click on JDK folder and click on info, copy the 'Where' location
Open your bash profile with following command vi .bash_profile
Once in VI editor, insert the following:
export JAVA_HOME=copied Where location from JDK folder followed by /Contents/Home
It should look something like below
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home
Now quit editor by :wq and restart your machine and you will now have JAVA in your system preference.
Hope this helps!!

Netbeans 10 not installing

I'm having issues trying to install NetBean 10 (incubating) on a laptop. I've checked that Java is installed, as well as JDK (jdk1.8.0_191). I've checked that Java is installed correctly by going to the command line and typing "java -version" and it correctly responds
java version "1.8.0_191"
Java(TM)SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
I've checked that the environment varible "JAVA_HOME" is correct (echo %JAVA_HOME%), and that the Path variable is correct.
However when I try installing NetBeans (from the C:\netbeans10\bin\netbeans64.exe) (yes, also double checked the laptop is correctly running Win10 64bit, it is) a logo for netbeans briefly appears, goes away after 1 sec, and nothing else happens.
I've tried downloading a fresh NetBeans, reinstalling Java, rebooting the system, disabled anti-virus, disabled firewall, tried from safe boot, however it just does not install.
Anyone have any ideas on what step I'm missing so that I can get this installed?
Thanks in advance.
A possible caused of your problem is that NetBeans is trying to run using a version of Java that does not exist on your machine. To eliminate this as a possibility:
Locate the file netbeans.conf. It will be in the etc directory within the NetBeans installation directory.
Open the file in any text editor. It is just a properties file containing name/value pairs,
Locate the line containing the text netbeans_jdkhome.
If the line is commented out delete the leading # character.
Set the value to the actual path to your JDK. For example, on my machine it would be: netbeans_jdkhome="C:\Java\jdk1.8.0_191".
Save the file and (re)start NetBeans. NetBeans will now use the JDK specified by the netbeans_jdkhome property.
If NetBeans still doesn't start then update your question with the content of the NetBeans log. See NetBeans - where to find the IDE log? for details on locating that file.
One other point: although you can run NetBeans 10.0 using JDK 8, I can't think of any good reason to do that. Most users will probably download and install JDK 11, and use that instead.

How to install openJdk 8 in windows 64 bit os

I need to install open JDK in my Windows 64-bit os. I have used ORACLE open JDK and downloaded from the below link: https://jdk.java.net/8/
While downloading I have selected Accept License Agreement and installed.
But, after the installation when I tried checking the version using command java -version it's showing like regular JDK.
Can anyone help me to get where I went wrong? Or is there any better vendor to install open JDK in windows. Thanks.
Amazon offers an open jdk for Windows (and other OS), but just for Java 8, 11 and 16.
You can download it from here: https://aws.amazon.com/es/corretto/
After installing it and running the java -version command, you will see something like this:
>java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment Corretto-8.242.08.1 (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM Corretto-8.242.08.1 (build 25.242-b08, mixed mode)
You need to set your java version in environment of you machine and target your JDK8 bin folder, or any JDK that you want to have at your disposal when you run java -version.
The best way to do this is to use the builds from adoptopenjdk. They're very high quality and come in multiple variants for Windows ranging from zip files to MSI installers. Dead simple to install JDK 8, 11 or 15.
But, after the installation when I tried checking the version using command java -version it's showing like regular JDK.
This is because JAVA_HOME is pointing to your old JDK. You need to go to Control Panel and change the Environment Variables. Just do a search on Windows 10 for "Environment Variables" to easily find that configuration panel.
Azul Systems provides builds of OpenJDK and relative installers, for all OSes and JDK versions.
It also provides builds of the JDK with OpenJFX included.
The installers bind JAR files to be executed by Java on Windows.
Download from azul.com website
I know this is old but should anyone run across this in search of OpenJDK 8 go here
https://developers.redhat.com/products/openjdk/download

Confusion about Java Versions

So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.

How to start eclipse with different version of Java?

I have here a computer (Windows XP) with java 1.4 and java 1.6 (I don't know why there is 1.4 on this system, probably they forget to uninstall it). Here is also Eclipse Helios.
Now if I want to start eclipse I get the message that Java 1.4 is too old. Huh? I have here also 1.6, Eclipse should start with 1.6
I checked the current Java Home via cmd
java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_0
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
Ok so somehow 1.4 is the standard java here. Fine, let's change standard java to 1.6 (because it's installed, so it should work). But wait, this is not working I don't have the rights to change that. Cannot change any standard java path. So what can I do? I figured out, that I can bypass the Eclipse message if I edit eclipse.ini the line -Dosgi.requiredJavaVersion=1.4 to -Dosgi.requiredJavaVersion=1.5 But at the end I'm using this eclipse with Java 1.4, and who knows what bugs or problems I'm getting with this. I have the path to java 1.6 , can I use this and start Eclipse, how? Any ideas?
You can add the -vm option to eclipse.ini:
-vm
C:/path/java/jdk1.7.0_03/bin/javaw.exe
It has to be on 2 separate lines and it has to be added before -vmargs.
You can configure it in the build path
Go to Eclipse(mac) / Window(for windows)
->Preferences
->Java
->Installed JREs
->JAdd the jdk/jre library you would like to add.
->click ok (Done)
Then the jdk is configured for the completed eclipse workspace.
You Can change the jdk for the individual project using the build path configuration.
To do that :
Select the project ,right click
->Choose the java Build Path.
->JRight hand side of the pane click the "Add Library"
->Choose "JRE system library"
->Select "Alternate JRE" (There u can see the list of the installed/configured JRE).
->Click Finish
Let know if still the problem exists.

Categories