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 component of JRE means that when I distribute a Java application which uses tools.jar
, I have to distribute it along with the application bundle OR include it in classpath.
My questions are:
- Does tools.jar contain platform-dependent components that prevent it from being distributed across different platforms (Windows/Linux/OSX)?
- 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? - 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?
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?
- In order to distribute
tools.jar
, you must redistribute the entire Oracle JDK, OR the entire JRE with just "The javac bytecode compiler" which includestools.jar
; that redistribution is allowed to be "bundled" with your app. - Redistributed JDK or JRE must be "complete and unmodified" (minus a couple sections about things you can add and/or subtract).
- You can never redistribute beta versions.
- You comply with the other general terms covered in the redistribution section of the license.
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:
- copy and distribute the program’s unmodified source code (Section 1)
- modify the program’s source code and distribute the modified source (Section 2)
- distribute compiled versions of the program, both modified and unmodified (Section 3) provided that:
- all distributed copies (modified or not) carry a copyright notice and exclusion of warranty (Section 1 and 2)
- all modified copies are distributed under the GPL v2 (Section 2)
- all compiled versions of the program are accompanied by the relevant source code, or a viable offer to make the relevant source code available (Section 3)
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
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.
来源:https://stackoverflow.com/questions/22305686/is-it-safe-to-distribute-tools-jar-along-with-a-java-application-bundle