Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

bluej

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 ?

like image 800
user310291 Avatar asked Aug 29 '15 21:08

user310291


1 Answers

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.

like image 143
J Richard Snape Avatar answered Sep 24 '22 16:09

J Richard Snape