java tools.jar包含,将tools.jar与Java应用程序包一起分发是否安全?

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 includes tools.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.

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)

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);

You can check if here if tools.jar is not present then show the message, else add it to the classpath programatically.

Shishir

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值