Although tools.jar
is not a component in JRE, but it comes with all major implementations of JDK such as Oracle JDK and OpenJDK.
Not being standard comp
Wouldn't it be easier just to require that a JDK be installed and $JAVA_HOME be set? It seems rather dangerous to package tools.jar with your app. It would then be the user's responsibility to get $JAVA_HOME on the $PATH however they choose to do it.
Short Answer: You cannot redistribute just tools.jar
either from Oracle JDK or from OpenJDK without redistributing whole bundle.
Detailed Answer below:
After reading few articles over internet, below are my findings about your questions:
Does tools.jar contain platform-dependent components that prevent it from being distributed across different platforms (Windows/Linux/OSX)?
There is no standard dependency defined for tools.jar
. I have written a sample program which runs perfectly on the Unix and Windows machines. I have copied tools.jar
from a Windows machine to a Unix machine. Everything works fine.
We already know that Oracle JDK does not allow distribution of tools.jar, but what about OpenJDK, can we distribute tools.jar from OpenJDK to avoid licensing issue?
tools.jar
, you must redistribute the entire Oracle JDK, OR the entire JRE with just "The javac bytecode compiler" which includes tools.jar
; that redistribution is allowed to be "bundled" with your app.Source: Can we redistribute Oracle tools.jar? Oracle JDK License: http://www.oracle.com/technetwork/java/javase/readme-142177.html#redistribution
If tools.jar cannot be distributed along with a Java application, is there a platform-independent way to determine its location, so that it can be put into classpath?
OpenJDK carries GNU General Public License, version 2, with the Classpath Exception. A licensee of GPL v2-licensed software can:
You can get more details of GPL v2 at The GNU General Public License v2 - An Overview
UPDATE: Locate & add tools.jar
into classpath.
If the end user is running the application using JDK, you will get the desired tools.jar
automatically. If not, then you need to suggest the user to install JDK
.
To check this through the program, you can make use of Eclipse JDT JARs. Below code shows how to locate the absolute path of the current JDK/JRE in JVM, and also to add the JAR to classpath
.
IVMInstall jre = JavaRuntime.getDefaultVMInstall();
File jdkHome = jre.getInstallLocation();
IPath toolsPath = new Path(jdkHome.getAbsolutePath())
.append("lib")
.append("tools.jar");
IRuntimeClasspathEntry toolsEntry =
JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath);
toolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
Source: Launching Java Applications Programmatically
You can check if here if tools.jar is not present then show the message, else add it to the classpath programatically.
Shishir