NetBeans - 在一个 jar 中部署所有内容 [英] NetBeans - deploying all in one jar

查看:19
本文介绍了NetBeans - 在一个 jar 中部署所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
将外部库放入 JAR?

我有 NetBeans 6.8,我写了一个类,它有两个库(jar 文件).构建它后,我得到了一个包含 project.jar 的dist"文件夹和一个包含两个 lib jar 文件的lib"文件夹.

I have NetBeans 6.8 and I wrote one class which has two libraries (jar-files). Building it, I get a "dist" folder with my project.jar and a "lib" folder which contains the two lib jar files.

我怎么能在一个 jar 文件中得到所有这些?(我不使用 Maven/Ant 或类似的东西.)

How could I get all this in one jar file? (I do not use Maven/Ant or something like this.)

推荐答案

基本问题是当前版本的 Java 不支持开箱即用的 jars inside jars.

The basic problem is that the current version of Java does not support jars inside jars out of the box.

推荐的解决方案是使用 jar 内 MANIFEST.MF 文件中的 Class-Path 行来指向所需的库(允许使用相对路径),然后将所有文件部署在一起并使用java -jar your.jar"调用它.罐子"

The recommended solution is to use the Class-Path line in the MANIFEST.MF file inside your jar to point to required libraries (relative paths are allowed) and then deploy all files together and invoking it with "java -jar your.jar"

如果您真的想要一个jar-inside-jar"解决方案,我们已经使用 one-jar 好几年了,但由于我们的目标 JVM 与上述解决方案配合得更好,所以我们不再使用它.

If you really want to have a "jar-inside-jar" solution, we have used one-jar for several years, but gone away from it since our target JVM worked better with the solution described above.

http://one-jar.sourceforge.net/

我将它与 Eclipse 中的 fatjar 插件一起使用.我没有将它构建到 Netbeans 中的任何经验,但是构建到一个 ant 脚本中很简单,我相信无论如何 NEtbeans 都会使用它.

I used it with the fatjar plugin in Eclipse. I do not have any experiences with building it into Netbeans, but it is simple to build into an ant script which I believe is what NEtbeans use anyway.

这篇关于NetBeans - 在一个 jar 中部署所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆