将所有 jar 合并或合并到一个可执行 jar 中 [英] Combine or merge all jars in one executable jar

查看:32
本文介绍了将所有 jar 合并或合并到一个可执行 jar 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是一个简单"的问题,但使用 Eclipse 做这样的事情似乎很复杂.

我有一个utils"项目,我在其中开发了通用"代码,例如 xml 解析器、记录器、数学计算、调试实用程序等.

这个库基于其他几个外部库(commons-lang-3.1、colt-1.2.0、jdom-2.0.4)来工作,它是一个不可运行的 JAR 文件(即,没有 main(),只是包含在其他项目中的实用程序代码).

我想要做的是,当我创建我的项目的JAR文件时,将JAR文件中的所有外部JAR(common-lang、colt、jdom)提取出来,以便在其他项目中自动使用它们.

>

原因是我不想在基于我的 lib 的每个项目中重新包含 common-lang、colt 和 jdom,而是使用打包在我的 lib JAR 文件中的那些(这是一种确保我将在基于我的库的项目中使用相同版本的库)

我知道如何使用可运行的 JAR 文件来做到这一点.参见例如:How to create a jar withEclipse 中包含外部库吗?

但在不可运行的 JAR 文件中:

  • 我所有的类都根据我创建的包正确导出到正确的目录结构中(希望 ;-)),
  • 但是外部 JAR 文件是按原样"导出的,所以当我在另一个项目中导入我的 JAR 时,无法看到那些 JAR(common-lang,...),我必须重新导入它们.

是否有一种简单的方法可以导出具有目录结构的 JAR 文件,其中所有外部 JAR 文件也被提取到生成的 JAR 文件中?

问候

解决方案

你见过 JarSplice 吗?>

JarSplice 通过易于使用的 GUI 将您所有的 jar 文件和本机文件合并为一个易于使用的可执行 jar 文件.

Kind of a "simple" question here, but it seems complicated to do such a thing using Eclipse.

I have a "utils" project, in which I have developped "common" code like xml parsers, loggers, maths calculations, debug utilities and such.

This library is based on several other external libs (commons-lang-3.1, colt-1.2.0, jdom-2.0.4) to work, and it's a non-runnable JAR file (ie, there is no main(), just utility code to include in other projects).

What I want to do is, when I create the JAR file of my project, extract all external JARs (common-lang, colt, jdom) in the JAR file, in order to automatically use them on other projects.

The reason is that I don't want to re-include common-lang, colt and jdom on every projects based on my lib, but use the ones packed in my lib JAR file (and it's a way to ensure that I'll be using the same version of those libs in the projects based on my lib, too)

I know how to do that with a runnable JAR file. See for instance : How to create a jar with external libraries included in Eclipse?

But in a non-runnable JAR file :

  • all my classes are correcly exported in a correct directory structure based on the packages I created (hopefully ;-)),
  • but external JAR files are exported "as-is", so when I import my JAR in another project, those JARs (common-lang, ...) can't be seen, and I have to re-import them.

Is there a simple way to export this JAR file with a directory structure in which all external JARs files are extracted in the generated JAR file, too ?

Regards

解决方案

Have you seen JarSplice?

JarSplice merge all your jars and native files into one, easy to use executable jar file via an easy to use GUI.

这篇关于将所有 jar 合并或合并到一个可执行 jar 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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