It seems the JDK installer on Windows 7 does not install a path variable to find javac. I can set it manually. But I do not like to change it with any new update of JDK. Does it use any other environment variable? Or is it really that weird?
I don't know of a JDK installer which sets the PATH on any system.
You can install several version of the JDK and if you use an IDE, you don't need to set the path. If you want to use javac manually (don't ask me why you would) you need to set the PATH to specific which version to use.
Yes You can using environment variables. Which available in Control panel -> system
Related
My school forces us to use Dr Java and I'm having trouble getting it to use the JDK compiler instead of the Eclipse compiler.
Reinstall JRE so that it will update JAVA_HOME, Path. Alternately, update JAVA_HOME, Path manually in advanced system settings (if using windows)
Then configure Dr Java to use the newly installed JDK
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.
I am shipping a executable jar file to customer, Customer has installed JRE 5, JRE 6 and JRE 7 on the box. My Jar required JRE 7 to run.
Without changing the system PATH (Environment var) how can I specify the JRE 7 to use?
You can specify full path to that JRE that you need, for example:
/path/to/jre/bin/java.exe -jar executable.jar
or
/path/to/jre/bin/javaw.exe -jar executable.jar
If you run this from a shell (script) then it is good practice to first set the JAVA_HOME environment variable to the right location before (/path/to/jre) before running the executable. You could first set/export JAVA_HOME and then extend it to the location of the Java executable (e.g. %JAVA_HOME%\bin\java.exe on Windows). More information here.
I'm not sure there's a cross-platform way to achieve this.
On Windows you can use a tool such as launch4j to wrap up the jar as a .exe that can select an appropriate JRE.
On Mac OS X you can have several different JDKs installed in parallel but only one public JRE (which will be at least the latest version out of the installed JDKs, and may be newer if it's been auto updated). It's the public JRE that is used for app bundles and when double clicking a JAR in finder.
The simplest way to do this, is to use Java WebStart to launch your program and then specify you need a suitably new version of Java. The launcher will then locate a suitable distribution on your system to use.
Using javaws also allows you to easily distribute new updates to your users.
Caveat: Caching has notoriously been a problem over the years. Ensure that when a jar changes content, its URL changes too.
So i decided to try the beta of android studio today, but it refuses to run on my 32-bit JRE. I can download the 64-bit JRE, but im not interested in it being my default JRE for various reasons (my current 32-bit eclipse IDE, Processing IDE and Minecraft doesn't like 64-bit to my experiences), and i think that swithing java_home dir all the time will be cumbersome.
So does intelliJ have some way of setting an alternative JAVA_HOME dir like eclipse does in its ini?
In IntelliJ you can specify which SDK to use at project level. go to "File" --> "Project Structure" --> SDKs (list on the left) and you can add/remove paths to different SDKs
Other solution: If you use Windows then I think you can specify JAVA_HOME as system property just for IntelliJ. If you use Linux the solution is similar.
I use IDEA_JDK for this purpose (on linux).
I believe it is STUDIO_JDK for android studio.
For more information on this and other jetbrains IDE's, see https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under
The other answers will not work for 64bit versions. Jetbrains have actually documented this quite well. From https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under:
Java 8
Please be aware that Java 8 is required to run IntelliJ IDEA starting from version 16 on all the supported platforms. It also applies to the lightweight IDEs released from the same branch (144+).
Windows
JDK is bundled with all the product installers and it's recommended that you will use the provided JDK version unless there are any specific issues.
32-bit JDK is located in IDE_HOME\jre directory and is used by the 32-bit product executable.
To run the IDE in 64-bit mode you will need to download and install 64-bit JDK (not JRE) distribution and install it yourself. IDE will find and use it from the registry when you run the 64-bit .exe file (available only for IntelliJ IDEA right now, other products can use the .bat file to run in 64-bit mode).
<product>.exe uses this JDK search sequence:
IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK environment variable (depends on the
product, WEBIDE_JDK applies to both WebStorm and PhpStorm before
version 2016.1)
..\jre directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
idea64.exe uses this JDK search sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
It’s also possible to start the IDE with .bat file located in the bin directory, it uses the following JDK search sequence:
IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK environment variable (depends on the product)
..\jre directory
JDK_HOME environment variable
JAVA_HOME environment variable
Environment variable must point to the JDK installation home directory, for example:
c:\Program Files (x86)\Java\jdk1.8.0_66
The actual JDK version used by the IDE can be verified in Help | About dialog (open any project to access the menu).
Define IDEA_JDK / PHPSTORM_JDK / WEBIDE_JDK / PYCHARM_JDK / RUBYMINE_JDK / CLION_JDK / DATAGRIP_JDK variable depending on the product to override the default version from IDE_HOME\jre.
Use Rapid Environment Editor to add/edit the variables, it will detect incorrect paths.
Linux
Starting from IntelliJ IDEA 16 and the most recent versions of the lightweight IDEs, we are bundling custom JRE with Linux distributions, just like we've been doing for Mac. Our custom JRE is based on OpenJDK and includes the most up to date fixes to provide better user experience on Linux (like font rendering improvements and HiDPI support).
Boot JDK path is stored in the .jdk file located in the config folder. It can be modified either via the Change IDE boot JDK action or by manually editing .jdk file (if you can't start the IDE to change it via an action).
It's recommended to use the bundled JRE (if available). In case you have any issues with the bundled version, you can switch to the latest version of Oracle JDK or OpenJDK available for your system (OpenJDK 1.6 is not supported, please use 1.7 or later versions, JDK 1.8 is recommended and older Java versions are not supported starting from IntelliJ IDEA 16).
Check bin/.sh file for the JDK search order, it's similar to Windows in terms of the environment variable names. It's a legacy way to adjust the boot jdk, use it for older product versions. Consider using .jdk file instead (see above), so that your modifications can survive IDE updates/re-installation.
Check this answer if you need to install the JDK manually on Linux.
If you have problems with ugly fonts, please see this thread comments for the tips.
Help | About will show the actual JDK version.
Mac OS X
Our latest IDE versions come with the bundled custom JDK 8 which contains the fixes for most known OpenJDK bugs. Should you need to use a different Java version, please refer to https://blog.jetbrains.com/idea/2015/05/intellij-idea-14-1-4-eap-141-1192-is-available/.
If you override IDE JDK version, its path is stored in .jdk file located in the config folder (idea.jdk for IntelliJ IDEA, pycharm.jdk for PyCharm, etc). Delete this file or change the path inside the file manually in case IDE no longer starts and you can't change it via the menu.
If IDE doesn't start and this file doesn't exist, create it manually and specify Java path to use (Java home location), for example:
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk
A reminder - once you set up a JAVA_HOME env variable in Windows, you need to close all your IntelliJ apps, and then start again. Otherwise, there might be troubles with accessing JAVA_HOME variable.
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.