Why eclipse need JAVA_HOME - java

I was reading some articles about how jvm works, and i tested that if i change the jre from Eclipse(installed JREs), the code will be executed in that jvm. So my question is why the eclipse needs to have JAVA_HOME set in environment variables. Does eclipse use that JRE in any form if i select another in Eclipse(installed JREs)

Eclipse does not require JAVA_HOME to be set, but as info for you, many MANY tools that you can find over the web use inter under the hood oracle tools, those will never run if your computer has no idea where they are located, JAVA_HOME is just a variable in the enviroment, so you( and the tools you use) can execute things like javac or java without telling every time where those are in the pc
.

Related

Changing between Java8 and Java7 Environments

I am trying to change between Java7 and Java 8 environments. I created the following new environment variables:
JAVA7_HOME - java 7 location
JAVA8_HOME - java 8 location
JAVA_HOME
I then set JAVA_HOME to be %JAVA8_HOME% or %JAVA7_HOME%. In path I have
%JAVA_HOME%\bin;REST OF PATH
It seems no matter what I set JAVA_HOME to it will not change the outcome of java -version, even for new sessions.
How can we have two separate java environments while easily changing between them? I've tried setting everything to the correct paths, that includes:
HKEY_CURRENT_USER\Environment JAVA_HOME
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment CurrentVersion
and even changing symlinks to point to the version we want. We've create batch scripts to do it all, we've create powershell/,net to do it and then broadcast, tried setting it all and restarting explorer.. It seems impossible to switch between 7 and 8.
Does anyone have an idea how to resolve this?
The basic problem is that changing environment variables via commandline is not permanent for some reason. You'll have to set the new value via the UI.
I used to do the following:
Put both the jdk8 and the jdk7 in your path (put the one you want as "default" first).
Look up java.exe and javac.exe in the jdk8 bin/ directory. Copy the executables under the name java8.exe and javac8.exe.
Do the same in the jdk7 bin/ directory, and copy the binaries to java7.exe and javac7.exe.
Now you can call java/javac, java7/javac7 and java8/javac8.
(I am not sure why anybody would need JAVA_HOME, I never set it.)
The other excutables like jar.exe and so on will be taken from the default jdk (the one first in the path), this is ok, since your JAR files will be the same no matter which jar.exe made them.
Then go on to configure the applications you need, like eclipse.
Hopefully, also your build tool can be told which executables to use. If not, it will use the default.
This way, you can also realize crazy configurations. For example, suppose you want jdk7 as default, but want to always use the java8 javadoc. Then simply rename the javadoc.exe from jdk7, for example to javadoc-dontuse.exe. This way, when you type javadoc.exe or some application calls it, it will not find it in the (default) jdk7 and continue to search in the jdk8 bin.

How JetBrain IntelliJ IDEA select Java to bootup

I have install Java 8 EA on my Window 7, but it's neither in my %JAVA_HOME% nor in the %PATH%. However when I start my IntelliJ IDEA v12 by clicking idea64.exe, it picked up java 8 EA instead of my Java SDK 1.6.0_32, which is in the %JAVA_HOME% and %PATH%.
Anyone know when IDEA started, how it decide which Java version to run?
It was picked from the registry.
When launched from .exe IDEA looks for Java in a following order:
IDEA_JDK (or IDEA_JDK_64) environment variable
jre/ (or jre64/) directory in IDEA home
registry
JDK_HOME environment variable
JAVA_HOME environment variable
When launched from .bat the order is same but registry isn't looked, and 64-suffixed vars aren't used (what is probably a bug).
Here is the available options that you can use for all the different operating systems. If you are interested.
http://intellij-support.jetbrains.com/entries/23455956-Selecting-the-JDK-version-the-IDE-will-run-under
You can add an additional environment variable called IDEA_JDK to target the specific JDK that you want Intellij to use.

Error message in trying to run java

Am getting the following error message while trying to run java. I have typed in java -version but am getting error:
C:\>java -version
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:C:\PROGRA~1\HP\QUICKT~1\
bin\JAVA_S~1\classes;C:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar
Error occurred during initialization of VM
Could not find agent library jvmhook on the library path, with error: Can't find
dependent libraries
Java is being invoked in a slightly abnormal way.
I have multiple answers depending on your Java version number and whether or not you wish to perform automated testing on your computer.
HP's Quick Test Professional (QTP, an automation tool) has been installed on your computer; this is the program which creates _JAVA_OPTIONS (and usually also IBM_JAVA_OPTIONS) to be what you observed in your post:
-Xrunjvmhook -Xbootclasspath/a:C:\PROGRA~1\HP\QUICKT~1\
bin\JAVA_S~1\classes;C:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar
QTP puts these in place so that it can recognize Java objects, allowing you test a Java application.
It also can create environment variable
JAVA_TOOL_OPTIONS with
-agentlib:jvmhook
which is required for working with Java 1.6
If you do not require QTP to perform tests against Java applications then you can experiment with removing these environment variables.
Pro-tip for easy reverting, just amend the Environment Variable names (e.g. rename _JAVA_OPTIONS to IGNOREME_JAVA_OPTIONS)
*Environment variables require local admin privileges and a system restart to take affect.
If you are using Java version 1.5 or older then you can probably get away with removing JAVA_TOOL_OPTIONS only.
The jasmine.jar seems to be troublesome to a number of java applications; I have had considerable difficulty with this stopping my applications from running in the past.
The _JAVA_OPTIONS environment variable is making some very serious modifications to your Java environment -- and obviously doing it wrong, since it's not launching. I don't know what is setting that environment variable, but if it's not something you're trying to do yourself, if I were you I'd make a note of the value just in case you need to restore it, then go to your Windows "System" Control Panel and remove _JAVA_OPTIONS altogether.
I'm using Intellij IDE. Removing .idea folder from project's local directory solved this issue.

JSmooth Java 1.4 or above not found error

I have installed JSmooth. My computer has JDK 1.7 & JRE 1.7. but it says need java 1.4 or above to open & try to download. Why is that ??
You need to set the JAVA_HOME environment variable to your JDK or JRE base path, e.g. C:\Program Files\Java\jdk1.8.0_91. For this, go to Control Panel -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> New.
I was initially confused by the same problem because java and javac were working on the command line so I thought all variables were set up but JAVA_HOME does not seem to be set by default when installing a JDK.
From the JSmooth documentation
Something goes wrong at launch-time, and the wrapper won't start my java application. How can I investigate?
The first thing to do, is to run the wrapper with the additional argument -JskelDebug=1 (the option is case-sensitive). This will start the wrapper in debug mode, displaying a console (or using the current one, for the console wrapper), and output many useful information.
I was also in the same problem for a whole night. I installed JVM again, JSmooth again, didn't happened any thing... Then I downloaded and installed this and suddenly it recognized JVM. I guess, to access JVM, this app need Microsoft VM... a rough guess though!

Why can't I set JAVA_HOME and JRE_HOME to something else?

I'm running ubuntu and djatoka (which runs in tomcat) won't work with OpenJDK. So I set JAVA_HOME and JRE_HOME to the Sun java that I downloaded and exported the variables. When I start tomcat, it reports JRE_HOME to what I set.
However, when I actually look at the variables, they're pointing to OpenJDK and djatoka isn't working. I can't find anyplace where it's being hardcoded, and even when I drop the variable assignments in catalina.sh and export from there, the same thing happens.
What the heck is going on? Thanks,
kyle
Did you start tomcat in the same session where you exported the value?
Did you manually install tomcat or did you apt-get it?
You can set the JAVA_HOME that tomcat must use in tomcat/bin/catalina.sh
You can also set it in /etc/environment. eg:
JAVA_HOME=/usr/lib/jvm/java-6-sun
https://help.ubuntu.com/community/EnvironmentVariables#System-wide environment variables
What operating system are you using? Try making sure you are setting those environment variables for the entire system and not the user.
Ubuntu uses a somewhat wired alternatives system. Program in /usr/bin point to /etc/alternatives and from there it goes to /usr/share/jdk-something.
There is an easy way: Uninstall the OpenJDK and GCJ. But you might run into dependency-issues.
Or read about the alternatives-system.
man update-alternatives
should help. It's not that hard. A little complicated - that's all.
I should add, that the benefit of the alternatives system is, that you can have multiple installations of java in parallel (1.5, 1.6, 1.7 alpha, OpenJDK) and switch with one command all the links - to java, javac, appletviewer, javap and so on. Not to forget the CLASSPATH, afaik. And Updates from 1.6.23 to 1.6.24 are handled by Ubuntu flawlessly. But it is annoying to trace the links down to their root.
There is even a Java-shortcut for the alternatives:
update-java-alternatives --help

Categories

Resources