如何使用 Ant 将库打包到我的 jar 中 [英] How to package libraries into my jar using Ant

查看:36
本文介绍了如何使用 Ant 将库打包到我的 jar 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序依赖于两个外部库,我都有 jar 格式并将它们添加到我的类路径中,从而可以在 NetBeans 中运行我的应用程序.

My application relies on two external libraries, I have both in jar format and have added them to my classpath, making it possible to run my application within NetBeans.

但是,我想将我的应用程序打包到一个易于使用的 jar 文件中.当我尝试 NetBeans 提供的 jar 创建的自动方法(它在 dist/ 中自动生成一个 jarfile)并在另一台计算机上运行它时,我得到了很多 ClassNotFound(或类似的)我可以判断的类的异常应该由我的其他库提供.

However, I would like to package my application in an easy to use jar file. When I tried the automatic method of jar creation provided by NetBeans (where it auto generates a jarfile in dist/) and ran it on another computer, I got lots of ClassNotFound (or similar) exceptions for classes that I could tell were supposed to be provided by my other libraries.

有没有办法将我拥有的其他 jarfile 包含到我自己的 jar 中?我以前从未创建过依赖于其他库的应用程序,所以这对我来说是第一次.

Is there a way I can include the other jarfiles I have into my own jar? I've never created an application which relies on other libraries before so this is a first for me.

推荐答案

您可以在 jar 的清单中添加Class-path"行.缺点是您必须硬编码清单中文件系统(而不是 jar)位置的路径.如果你把它们都放在同一个目录或一致的相对目录中,应该是可以管理的.

You can add a "Class-path" line to your jar's manifest. The drawback is that you have to hard code the paths to a file system (not jar) location in the manifest. If you put them all in the same directory or a consistent relative directory, it should be manageable.

参见:http://docs.oracle.com/javase/教程/部署/jar/downman.html

或者,您可以尝试使用 One-JAR:http://one-jar.sourceforge.net/

Alternately you can try something line One-JAR: http://one-jar.sourceforge.net/

这篇关于如何使用 Ant 将库打包到我的 jar 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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