Find out what JVM Eclipse is running on - java

I'm currently trying to tune my Eclipse installation and bumped into the "-vm" option. Other posts on SO mentioned that it's good to always use the latest JVM available because they keep getting better in terms of performance, so I'm likely to do that. I was wondering though how you could find out what JVM Eclipse runs on if you are not specifying the "-vm" parameter.
I found the following in the docs but that doesn't clarify how it will look for a JVM:
when passed to the Eclipse executable, this option is used to locate the Java VM to use to run Eclipse. It must be the full file system path to an appropriate Java executable. If not specified, the Eclipse executable uses a search algorithm to locate a suitable VM. In any event, the executable then passes the path to the actual VM used to Java Main using the -vm argument. Java Main then stores this value in eclipse.vm.

Actually, Windows->Preferences->Java->installed doesn't show you the one Eclipse runs under, but only the default JRE that it runs things under.
To see the one Eclipse is runing under, go to Help->About Eclipse Platform->Configuration Details, and look for the property eclipse.vm.
For example:
eclipse.vm=C:\Program Files\Java\jre6\bin\client\jvm.dll

According to this thread and this one:
eclipse will try to locate your JVM used for launching itself by examining your path.
So, you can:
Create a JAVA_HOME environment variable, that points to your actually preferred JDK.
This way you can easily choose between JDKs installed.
Put %JAVA_HOME%\bin in the path, anywhere preceeding <windowsroot>\system32, which also
contains java, javaw & co binaries.
This way the java* in the JDK bin directory is invoked whenever it is invoked from the path.
I believe the other posts tell you how to find what JVM eclipse is using.
However, I interpreted your question as: "what JVM will eclipse will use when launching itself ?" when no -vm args is used.
After further research, it appears that eclipse will look for a JRE:
either directly under its installation directory (<eclipse>\jre): if you copy the content of any installed JRE in that sub-directory, it will be selected
in C:\Program Files\Java\JRE....
in the %PATH% (see above)
Also read this SO answer to see why eclipse will by default select jvm.dll instead of javaw.exe

If you go to Help->'About Eclipse Platform' and click on the 'Configuration Details' button it will take a moment to display, but you get a dump of everything eclipse is configured for...
I found these 2 lines to be what you're looking for:
-vm
C:\Program Files\Java\jdk1.6.0_10\bin..\jre\bin\client\jvm.dll

I think if you do:
Window->Preferences->Java->Installed JREs you'll see a list of JREs on your machine.
The one that's checked is the one that eclipse is using.
Alternatively, if you go into the "run configurations" dialog, and look at the JRE tab, you can pick a JRE to run on there.

Related

Why can't BlueJ take into account my Java Home whereas Eclipse can

I want to install BlueJ manually for portability reason. I have set Java_Home and add Java bin directory to path environment variable. I'm using a symlink on c:\java which points to d:\java on sd card.
Why BlueJ does not take them into account still pretending it cannot detect jdk.
Update : Eclipse is OK so is there something specific with BlueJ and Jdk 1.8 ?
I've just done a clean install of BlueJ and JDK 1.8 on separate drives to replicate your problem. I made a symlink to the JDK and put that in JAVA_HOME and PATH (from your use of C:\ syntax, I guessed you were on Windows, so I tested on Windows 8.1).
I too found that the setting of environment variables was ignored by BlueJ in selecting a JDK to use when it is running. I could change JDK by using the companion program Select BlueJ VM, but could not enter a symlink there (I believe on earlier versions, changing VM was a setting on the start menu, not a separate program).
In summary:
It is not a problem with BlueJ and Java 8 compatibility
It is not a problem with the symlink
For Windows at least, It is due to the way that BlueJ determines and stores which JDK it uses (both actions via the registry).
You can manually change the registry key to your symlink if you want (see details below), but that's an extra install step.
In detail
I found that BlueJ stores that path to the JDK it uses in the following registry key
HKEY_CURRENT_USER\Software\BlueJ\BlueJ\3.1.5\CurrentVM
Note the root could be HKEY_USERS or HKEY_LOCAL_MACHINE depending on whether you installed for one user or all users of the machine.
The issue is that this key is set automatically if your system has only one VM available at runtime, or on the first run of BlueJ or with the Select BlueJ VM program at any time later. The options offered to you there are the JDK's that the launcher can detect (via the registry) on your system at that moment. Once that value is set, it is not changed dynamically at runtime to reflect JAVA_HOME. Even using the "Browse" option from the options, I could not set the symlink as the JDK location via the GUI.
You can, however, manually change the value of that registry key (e.g. via regedit) to your symlink value (tested and verified OK - might need administrator permissions).
I looked at the source code to determine how CurrentVM is set.
After a fairly short trawl (kudos to BlueJ devs for good naming), I eventually worked out that the actual code used to launch BlueJ is the C++ file in \package\winlaunch\bjlaunch.cc (source file mercurial link here).
That simply checks for the value of the registry key and, if it doesn't exist, if calls findRegistryVMs(), which checks the registry (NOT environment variables) for available VMs and offers those to the user. So, there doesn't appear to be a way to get BlueJ to use the value from JAVA_HOME without a manual registry edit.
N.B. If you do manually change this key value to the Symlink, you can change where the symlink links to and (with a restart) BlueJ will use whichever JDK the symlink linked to. Again, tested and verified on Windows 8.1
N.B. 2 At first, things looked optimistic: in Installer.java there is a method called findJavaPath() that first checks
String javaHome = System.getProperty("java.home");
before having a few guesses if that doesn't work. So it looks like it should respect the value of JAVA_HOME at install time. However, it seems to only use that to check that there is a compatible (1.6+) version of Java available.

How to make Eclipse search for JDK on another drive

So I've been getting this error when trying to start Eclipse:
"No java virtual env found after searching the follow locations:
/absolute/path/to/jre6/bin"
I checked the control panel and I got JDK (Update 21 / 64-bit) installed.
However, JDK is installed is installed on my primary drive (the sdd with Windows on) whereas Eclipse is unzipped and executed from my secondary hard drive.
How to I tell eclipse to find Java on my c-drive instead of the d-drive where it's located?
Thanks in advance!
I would suggest you uninstall all versions of Java you have installed and then installed the one you want to use.
Another option is to tell eclipse which Java to use. For example: eclipse -vm c:\path\to\jre\bin\javaw
Locate the eclipse.ini file and ensure that the variable -vm is correct (
FAQ How do I run eclipse):
If a JVM is installed in the eclipse/jre directory, Eclipse will use it; otherwise the launcher will consult the eclipse.ini file and the system path variable. Eclipse DOES NOT consult the JAVA_HOME environment variable.

Where does Eclipse default to look for the JDK/JRE to use?

I have four or five difference java installations on my Linux computer. I have set the JAVA_HOME in the bash_profile and bashrc to point to the latest version but whenever I install eclipse it finds a really old version that was installed and ignores the $JAVA_HOME. Is there another system variable it's looking at to pick that one? How do I fix this?
When launching, Eclipse looks for a JVM first in a jre/ directory directly below the locaiton of the eclipse executable. If that isn't found, it will consult the eclipse.ini file. If there's no -vm argument in eclipse.ini, it will look on the system $PATH environment variable to find a java executable. As you probably know, the command "which java" will show you what java executable is found first on your $PATH.
This is all described in these pages:
http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Find_the_JVM
http://wiki.eclipse.org/Equinox_Launcher#Finding_a_VM.2C_Using_JNI_Invocation_or_Executing_Java
But you should take note that the overwhelmingly recommended way to get Eclipse to use a specific JVM is to specify it in eclipse.ini as described here.
In eclipse.ini add :
-vm
%Path to java exec%
I don't remember if it should be the first argument, but add it first just to make sure. The file is located in your eclipse installation folder.
To explicitly specify a JVM of your choice, you can use the -vm command line argument:
eclipse -vm c:\jre\bin\javaw.exe ''start Java by executing the specified java executable
eclipse -vm c:\jre\bin\client\jvm.dll ''start Java by loading the jvm in the eclipse process
More information here .
As mentioned in Eclipse official FAQ : Eclipse DOES NOT consult the JAVA_HOME environment variable.

A JRE or JDK must be available in order to run Eclipse. No JVM was found after searching the following locations

Eclipse is unable to open, have used eclipse before and has open before without a problem. Now I keep getting the following error message:
A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations:
Have gotten eclipse to open and work on projects before and won't open.
Here is a screen shot of what I keep getting:
You can explicitly tell Eclipse where to find it. Open eclipse.ini and add the following lines to the top of the file:
-vm
/absolute/path/to/jre6/bin
Update: I just nailed down the root cause on my own Windows machine. The GlassFish installer complained with exactly the same error message and after digging in GlassFish forums, the cause was clear: a corrupt JRE install on a Windows machine. My JRE came along with the JDK and the Java 6 JDK installer didn't install the JRE properly somehow. A DLL file was missing in JDK's JRE installation. After I reinstalled the standalone JRE from http://java.com, overwriting the old one, the GlassFish installer continued and also Eclipse was able to start flawlessly without those two lines in eclipse.ini.
I got this problem because i uninstalled the jdk version 13 and reinstall the jdk version 8
Even though i have updated the path variables eclipse still pick the old configuration.
You need to edit the eclipse.ini file which is in your folder where eclipse.exe is placed.
Just update this file with the latest path so eclipse can pick it up
It usually is because:
you indicated the wrong jvm path in your -vm argument: see this SO question for an concrete example.
the eclipse.ini got corrupted somehow (if it hasn't been modified, this isn't it, but if setting a jvm path doesn't work, ... I would replace the eclipse.ini by one coming from a fresh installation just to be sure)
the java which eclipse search by default is no longer accessible (because the $PATH is no longer up-to-date)
More details on the wiki page "Finding a VM, Using JNI Invocation or Executing Java"
No -vm specified
When no -vm is specified, the launcher looks for a virtual machine first in a jre directory in the root of eclipse and then on the search path.
If java is found in either location, then we look for a jvm shared library (jvm.dll on window, libjvm.so on *nix platforms) relative to that java executable.
If a jvm shared library is found we load it and use the JNI invocation api to start the vm.
If no jvm shared library is found, we exec the java launcher to start the vm in a new process.
As mentioned in "FAQ How do I run Eclipse?":
Eclipse DOES NOT consult the JAVA_HOME environment variable.
So I would check your $PATH, starting by n new shell sesion (whatever your OS is), typing 'java -version' to see if it still returns anything.
Copy javaw.exe from C:\Program Files\Java\jre1.8(or)1.6(or)1.7\bin
and paste it inside Eclipse folder
where eclipse.exe is there. That's all.
Here is how I fixed mine:
find the location where your jre is installed. in my case, it was located at C:\Program Files\Java\jdk1.7.0_10
copy the jre folder and paste it where your eclipse files are located (where eclipse.exe is located).
when you download eclipse, you get a .zip package containing eclipse.exe and all the other files needed to run eclipse but it is missing the jre files. so all you need to do is to find where jre folder is located on your hard drive and add it to the rest of the eclipse package.
I had the same problem and the issue was that I had a 32 bit version of Eclipse running on my 64 bit machine and it wanted the 32 bit version of JRE.
I changed Program Files to Program Files (x86) in the eclipse.ini file like so:
-VM
C:Program Files (x86)\Java\jre6\bin
and that solved the problem.
You may want to just install the 64 bit Eclipse, but this will take care of the error.
Did you install Java via the java.com web browser auto install? If so, then that's your problem! You need to to the "manual" install: http://www.java.com/en/download/manual.jsp
It's just a matter of having the correct match of 32-bit Eclipse/32-bit Java or 64-bit Eclipse/64-bit Java. Many 64-bit Windows have 32-bit browsers and the latter is the version of Java that the auto-installer will provide - not what the 64-bit Eclipse wants.
Make sure the install path of JDK is in your Path variable in Windows.
adding -vm C:/Program Files/Java/jdk1.6.0_29/bin/javaw.exe to the .ini file helped me.
Is so simple,only add your java path for example:
C:\Program Files\Java\jdk1.8.0_121\bin
in PATH system variable
I have faced the similar issue earlier with Eclipse and STS IDE'S
Please check weather JDK/JRE is available or not in your machine. If not please install JDK and setup the environment variables.
Even after step 1, if you are still facing the issue then it's time to set the vm argument in eclipse.ini or sts.ini in the following way.
-vm
C:Program Files (x86)\Java\jre8\bin
I also had same problem when developing android applications using eclipse IDE.
I solved it by removing all the java installations (I had java 6 and 7 both) and re-install only jdk 7.
I got this fixed by doing the below steps,
1)
The eclipse finds the JAVA executables from 'C:\ProgramData\Oracle\Java\javapath'
The folder structure will contain shortcuts to the below executables,
i. java.exe
ii. javaw.exe
iii. javaws.exe
For me the executable paths were pointing to my (ProgramFiles(x84)) folder location
I corrected it to Program Files path(64 bit) and the issue got resolved
Please find the screenshot for the same.
Just to add on top of other answers:
Windows Users: You can give the PATH to JRE in eclipse.ini separated by '/' or '\'. It doesn't matter. Eclipse will pick it anyway. For example, in my windows system, either of the paths is fine (after -vm of course):
C:/Program Files/Java/jre1.8.0_181/bin
or C:\Program Files\Java\jre1.8.0_181\bin
Change the vm value in eclipse.ini file with the correct path to your JDK something like this,
-vm /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home/bin
Path to eclipse.ini looks to me something like this,
/Users/tomcat/eclipse/jee-2018-09/Eclipse.app/Contents/Eclipse
This sometimes happen if you remove Java from your path variables.
To set the PATH variable again, add the full path of the jdk\bin directory to the PATH variable. Typically, the full path is:
C:\Program Files\Java\jdk-11\bin
To set the PATH variable on Microsoft Windows:
Select Control Panel and then System.
Click Advanced and then Environment Variables.
Add the location of the bin folder of the JDK installation to the
PATH variable in system variables.
I had this problem too on a win7 machine.
I wanted to update the jre with a jdk. So i deleted the jre folder and downloaded and unzipped the new jdk.
The issue was i manually deleted the jre folder, when instead i should've uninstalled it. This leaves a bunch of registry entries that still point to the old jre. Somehow eclipse still wants to use the old jre.
I couldn't uninstall the old java vm, i kept getting this error:
Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor
So i had to use this MS utility to fix the uninstall:
http://support.microsoft.com/kb/2438651/
Then i had to install again the vm. I installed to the same location the original one was at, to avoid losing another hour! After that eclipse started correctly.
Julio
I just had this problem and fixed it this way. I noticed the error message has jre in it not jre6 or jre7, so i copied jre6 from program files to eclipse folder then renamed it from jre6 to jre, then it worked :p
Newb move on my part, but I had installed just the JRE instead of JDK. Installed JDK and my problem went immediately away.
I had this problem and it was due to my windows machine playing up. I went into control panel -> system -> advanced - environment variables.
I edited the PATH variable (which was already correctly set up), changed NOTHING, clicked OK to come back out of the screens.
Then eclipse worked. No idea why, except because windows. Hopefully this may help someone.
I had this issue; I fixed it by going to
Computer-->Properties-->Advanced Settings-->Environmental Variables
In the System Variables find the variable named PATH.
-->Select Edit
-->At the very end of the Path Variable, put a ";" then add your path of your JDK and put \bin\ at the end
Should be fixed.
Example:
System Variable-
C:\Program Files (x86)\Common Files.......HP\LeanFT\bin
JDK path-
C:\Programs Files\Java\jre1.8.0_121
Final Path -
C:\Program Files (x86)\Common Files.......HP\LeanFT\bin;C:\Programs Files\Java\jre1.8.0_121\bin\
Sources:
https://www.java.com/en/download/help/path.xml
Its simple.
JDK bin directory or JRE bin directory should be in path variable
Example :
Java Installed directory:
Assume your java installed in 'C:\Program Files\java\Jdk1.8.0_144' directory
Now you can find bin directory in 'C:\Program Files\java\Jdk1.8.0_144\bin'
Navigate to user's environment variable
Control Panel --> User Accounts --> User Accounts --> Change my environment variables
In popup click Path under User variables for section
Click Edit... button and another popup will appear
Click New button and enter C:\Program Files\java\Jdk1.8.0_144\bin
Click OK button and again OK button in Environment variables popup.
Now you can open your eclipse without error
I found a solution wherein the Eclipse.ini the location was the old version of Java, and after updating the new version of java the location of
-vm
C:\Program Files\Java\jre1.8.0_201\bin
was same so I had to change the directory to my new version of Java.
So solution is to just open the most updated Java version and copying its directory path and replacing it in the Eclipse.ini file.
Moderately future proof example for Linux-like systems. Assuming javac installed and on your path.
./eclipse -vm dirname $(readlink -f $(which javac))
This will find the directory where javac is installed, and pass as vm argument to eclipse.
If on Linux (ex: Ubuntu 18), try installing (or reinstalling in your case?) default-jre, as follows:
sudo apt update
sudo apt install default-jre
I had the same error when just trying to run the Eclipse installer (./eclipse-inst) on a fresh Eclipse download just now, and the installer wouldn't even run! Installing default-jre solved it!
Source:
https://linux4one.com/how-to-install-eclipse-ide-on-ubuntu-18-04/
In my case I had edited the eclipse.ini for a different purpose to include -vm parameter. That was causing the failure. I removed the -vm and following line where I had included \bin and that fixed the problem.
I got ERROR:
RESOLUTION :
in file eclipse.ini at below location :
make change as :
-vm
C:/Program Files/Java/jdk1.8.0_251/jre/bin/server/jvm.dll
Restart eclipse and error will be resolved
C:\Program Files\Java\jre1.8.0_221\bin
worked for me

How do I make the JDK the default JRE?

I use Eclipse with ant scripts, and Eclipse works well with the default JRE installation on Windows XP.
The annoyance comes when I want to run ant scripts compiling with the javac-tag, where it fails because there is no tools.jar in the classpath.
I've gotten the idea that if I could make the JDK become the default Java on Windows, then I would have what I have today, plus ant working out of the box.
Can this be done? What have I missed in the installation process?
Edit: I know of JAVA_HOME, but that is tedious and error prone (manually updating environment variables when a fresher JDK is available is not always something I remember).
Edit: I ended up figuring out how to make the javac task use the Eclipse compiler (ecj.jar), which works very nicely.
Edit: Maven also supports using the Eclipse compiler, but this appears to be very rarely used and with an old version of ecj.jar. I intend to look in to this at a later time.
Edit: Using ecj with maven-compiler-plugin 3.0 works very well, and allows for building with a JRE.
Edit: I had problems with the javadoc tool crashing when parsing bytecode generated by ecj.
The answer is "no," there is no way to get the JDK to be the default JVM upon install.
As the other answers point out, you can adjust your path and your JAVA_HOME to point to the JDK, or a different JVM entirely. This is in fact what the Java installation does in the first place.
However, your problem is that you want tools.jar to be found. To do this you can copy it to the ext directory under your default JVM. Check the JDK file structure here. This will probably work.
On the other hand, if modifying the JAVA_HOME and PATH variables for Java seems annoying, remember that it's just one of a series of things we do to keep us sharp
Download JDK from the website
Once everything is finished, go to Control Panel
Open JAVA
Click on the Java tab and select View
There will be one item present in the list. Change the Java Path from JRE to the JDK you downloaded, like so:
C:\Program Files\Java\<your_jdk_version>\bin\java.exe.
For example, mine looks like this:
C:\Program Files\Java\jdk1.7.0_07\bin\java.exe
Copying the tools.jar file to a location where Eclipse is looking for it may work, but is messy and fragile since that's a step you may not remember the next time you upgrade your JDK. Better is to convince Eclipse to look for it in the proper location.
Setting JAVA_HOME to the correct location works for some tools, but Eclipse does not honor it.
A couple of things to try:
Make sure your JDK is identified and
selected under
Preferences->Java->Installed JREs.
Make sure Ant is being invoked by the
JDK. One clue is that at the top of
the Console output you should see the
path of the javaw.exe which is being
used. If that path is in the JRE,
more convincing is needed. Check
Run->External Tools->External Tools
Configurations->[your Ant build]->JRE
and make sure the settings there
point to the JDK.
Try changing the JAVA_HOME environment variable to point to the JDK instead of the JRE.
Alternatively or possibly additionally, add a PATH entry to the JDK bin directory before any of the Windows system directories.
I suspect JAVA_HOME is enough to get Ant working, but it's sometimes nice to get the JDK version of java etc on the path too, so that when you just run java from the command line, you'll get exactly the same version as when you run javac.
You could probably write a WSH script to reconfigure your path automatically.
This JScript script just prints some info:
//file: jdk.js usage: cscript /Nologo jdk.js
var objShell = WScript.CreateObject("WScript.Shell");
function setJdk(version) {
try {
var jdk = objShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\" +
"JavaSoft\\Java Development Kit\\" + version + "\\JavaHome");
if(jdk != null && jdk != "") {
jdk += "\\bin";
var path = objShell.RegRead("HKEY_CURRENT_USER\\Environment\\Path");
path = jdk + ";" + path;
WScript.Echo("Could set PATH to " + path + "\n");
}
} catch(err) { /*probably key does not exist*/ }
}
setJdk("1.7");
setJdk("1.6");
setJdk("1.5");
There is a RegWrite method that can be used to write to the registry. There is a bit of work involved determining the latest version and rejigging the path, removing obsolete entries and sorting out system versus user paths. No doubt it could be used to set JAVA_HOME too. The JDK entry would need to appear before the system32 directory, as the JRE installer puts a java.exe in there.
(I'm not 100% sure if the shell would pick up on such changes or whether a reboot/env variable reload of some kind would be required.)
This is normally done by setting your JAVA_HOME environment variable to the root JDK directory that you want to use.
For example from a command line or batch file you simply do something like:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_14
However to set JAVA_HOME permanently add it to the environment variables on the Advanced tab in the property sheet for My Computer.
Apparently Eclipse can compile without the tools.jar. My guess it that they have a specific javac command that can work with a JRE (and not a JDK); this could be the reason why they can list their warnings.
Anyway, I would go the standard way (as suggested above) and install a JDK on your system. You can even start Eclipse with that specific JDK (without any JAVA_HOME change) by tweaking the eclipse.ini file (see these instructions).
Of cause this is doable. Not understand why people said No to this question.
Copy over the tools.jar is not a wise way, I had the issue when using eclipese,
Just add the jdk instead of jre to my build path and it works.
Here is the details:
http://www.gamefromscratch.com/post/2011/11/15/Telling-Eclipse-to-use-the-JDK-instead-of-JRE.aspx

Categories

Resources