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.
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.
I am trying to install java from install shield script
1) I have no other version of Java in my PC and When I install Java 7 silently it installs correctly
2) If I have any other java version already installed in my PC and I try to install Java 7 silently it fails
Do we have an option to install java silently even though it detects another version of java is already installed?
Why is the install failing?
The first thing you should probably do is find out for sure why the JRE install is failing.
The Windows version of it takes some command-line parameters that may be of some use to you. For logging /L <path_to_log> will create a log file.
I usually extract the MSI from the EXE's that Oracle makes available. Using the MSI directly allows you to specify install properties without having to please InstallShield's goofy command-line syntax. If you launch the EXE downloaded from Oracle (but don't proceed—just let it extract itself), look in the user's AppData\LocalLow\Sun\Java directory for a dir corresponding to the version of Java whose installer you just launched (e.g. jre1.7.0_25). Get the MSI and other files from there.
With the MSI, you can specify logging options on the command-line, like msiexec /i <jre_msi_file> /lxv* C:\temp\jre_install.log.
I'm pretty sure I've seen instances where JRE installers will effectively block the installation of an older ("less secure") version. It might be that this is what's happening in your case. You should see an indication of such in the install log file. If that's the case, I think there's a registry key that you can remove to "unblock" the install.
Static vs. Patch-in-Place
Another potential source of trouble is the type of install you want (or previously used). Oracle has two install methods that you may need to expressly specify when you install it.
A patch-in-place install always leaves a single version of the JRE installed, removing the old one (or upgrading it—I'm not certain about the details of how it's done) and leaving the new one in its place. This is the default behavior, and is probably what you will want to use. Browsers can only use one version of Java at a time, so there's not much reason to have older versions around if you're only interested in having Java in the browser.
A static install creates a new install of Java for every unique version number. This would be useful if you needed to be able to choose among some precise versions of Java for specific applications. Programs relying on quirky/undocumented behavior of specific Java VM implementations might need to use such an installation. In general, though, this kind of thing should be avoided, if for no other reason, than to avoid leaving JRE versions with known (and actively exploited) security vulnerabilities.
You can specify which install type on the command-line with STATIC=0 (a patch-in-place install) or STATIC=1. This should work with either the EXE or the MSI.
We have a couple of applications running on Java 5 and would like now to bring in an application based on Java 6. Can both java versions live together under Windows?
Is there any control panel to set the appropriate Java version for different applications, or any other way to set up, what version of Java will be used to run that particular application?
Of course you can use multiple versions of Java under Windows. And different applications can use different Java versions. How is your application started? Usually you will have a batch file where there is something like
java ...
This will search the Java executable using the PATH variable. So if Java 5 is first on the PATH, you will have problems running a Java 6 application. You should then modify the batch file to use a certain Java version e.g. by defining a environment variable JAVA6HOME with the value C:\java\java6 (if Java 6 is installed in this directory) and change the batch file calling
%JAVA6HOME%\bin\java ...
I was appalled at the clumsiness of the CLASSPATH, JAVA_HOME, and PATH ideas, in Windows, to keep track of Java files. I got here, because of multiple JREs, and how to content with it. Without regurgitating information, from a guy much more clever than me, I would rather point to to his article on this issue, which for me, resolves it perfectly.
Article by: Ted Neward: Multiple Java Homes: Giving Java Apps Their Own JRE
With the exponential growth of Java as a server-side development language has come an equivablent
exponential growth in Java development tools, environments, frameworks, and extensions.
Unfortunately, not all of these tools play nicely together under the same Java VM installation. Some
require a Servlet 2.1-compliant environment, some require 2.2. Some only run under JDK 1.2 or above,
some under JDK 1.1 (and no higher). Some require the "com.sun.swing" packages from pre-Swing 1.0
days, others require the "javax.swing" package names.
Worse yet, this problem can be found even within the corporate enterprise, as systems developed using
Java from just six months ago may suddenly "not work" due to the installation of some Java Extension
required by a new (seemingly unrelated) application release. This can complicate deployment of Java
applications across the corporation, and lead customers to wonder precisely why, five years after the
start of the infamous "Installing-this-app-breaks-my-system" woes began with Microsoft's DLL schemes,
we still haven't progressed much beyond that. (In fact, the new .NET initiative actually seeks to solve the
infamous "DLL-Hell" problem just described.)
This paper describes how to configure a Java installation such that a given application receives its own,
private, JRE, allowing multiple Java environments to coexist without driving customers (or system
administrators) insane...
It is absolutely possible to install side-by-side several JRE/JDK versions. Moreover, you don't have to do anything special for that to happen, as Sun is creating a different folder for each (under Program Files).
There is no control panel to check which JRE works for each application. Basically, the JRE that will work would be the first in your PATH environment variable. You can change that, or the JAVA_HOME variable, or create specific cmd/bat files to launch the applications you desire, each with a different JRE in path.
We can install multiple versions of Java Development kits on the same machine using SDKMan.
Some points about SDKMan are as following:
SDKMan is free to use and it is developed by the open source community.
SDKMan is written in bash and it only requires curl and zip/unzip programs to be present on your system.
SDKMan can install around 29 Software Development Kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x.
We do not need to worry about setting the _HOME and PATH environment variables because SDKMan handles it automatically.
SDKMan can run on any UNIX based platforms such as Mac OSX, Linux, Cygwin, Solaris and FreeBSD and we can install it using following commands:
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Because SDKMan is written in bash and only requires curl and zip/unzip to be present on your system. You can install SDKMan on windows as well either by first installing Cygwin or Git Bash for Windows environment and then running above commands.
Command sdk list java will give us a list of java versions which we can install using SDKMan.
Installing Java 8
$ sdk install java 8.0.201-oracle
Installing Java 9
$ sdk install java 9.0.4-open
Installing Java 11
$ sdk install java 11.0.2-open
Uninstalling a Java version
In case you want to uninstall any JDK version e.g., 11.0.2-open you can do that as follows:
$ sdk uninstall java 11.0.2-open
Switching current Java version
If you want to activate one version of JDK for all terminals and applications, you can use the command
sdk default java <your-java_version>
Above commands will also update the PATH and JAVA_HOME variables automatically. You can read more on my article How to Install Multiple Versions of Java on the Same Machine.
It should be possible changing setting the JAVA_HOME environment variable differently for specific applications.
When starting from the command line or from a batch script you can use set JAVA_HOME=C:\...\j2dskXXX to change the JAVA_HOME environment.
It is possible that you also need to change the PATH environment variable to use the correct java binary. To do this you can use set PATH=%JAVA_HOME%\bin;%PATH%.
I use a simple script when starting JMeter with my own java version
setlocal
set JAVA_HOME="c:\java8"
set PATH=%JAVA_HOME%\bin;%PATH%;
java -version
To have a java "portable"
you can use this method here:
https://www.whitebyte.info/programming/java/how-to-install-a-portable-jdk-in-windows-without-admin-rights
Or use links. While it is rather unpleasant to update the PATH in a running environment, it's easy to recreate a link to a new version of JRE/JDK. So:
install different versions of JDK you want to use
create a link to that folder either by junction or by built-in mklink command
set the PATH to the link
If other version of java is to be used, delete the link, create a new one, PATH/JAVA_HOME/hardcoded scripts remain untouched
Invoking Java with "java -version:1.5", etc. should run with the correct version of Java. (Obviously replace 1.5 with the version you want.)
If Java is properly installed on Windows there are paths to the vm for each version stored in the registry which it uses so you don't need to mess about with environment versions on Windows.
If you use Java Web Start (you can start applications from any URL, even the local file system) it will take care of finding the right version for your application.
Using Java Web Start, you can install multiple JRE, then call what you need.
On win, you can make a .bat file:
1- online version:
<your_JRE_version\bin\javaws.exe> -localfile -J-Djnlp.application.href=<the url of .jnlp file.jnlp> -localfile -J "<path_temp_jnlp_file_.jnlp>"
2- launch from cache:
<your_JRE_version\bin\javaws.exe> -localfile -J "<path_of_your_local_jnlp_file.jnlp>"