我正在开发一个具有自己的库依赖项的库,我想从中抽象出来。将项目导出到具有以下结构的 jar 后,我遇到了问题:
Foo.jar
-> net
-> foo
-> java class files
-> lib
-> *.jar
-> src
-> foo
-> java source files
-> doc
-> javadoc and other docs
-> License.txt
当我去测试我的库时,我可以轻松地从 net.foo.*
导入我的库代码,但在运行时会抛出异常,因为“没有合适的驱动程序......”并且其他依赖于从我的抽象层调用的内部库。
我正在使用 ANT 构建我的 jar,但不知道该怎么做。理想情况下,用户只需将我的 jar 添加到他们的构建路径,然后导入我的包。
最佳答案
您正在发布一个具有一组依赖项的库。库的用户可以选择添加依赖库。如果我理解正确的话,您希望通过将依赖项 jar 包含在库 jar 中来使用户变得简单。您可以使用 JarJar 将多个 jar 合并到单个 jar 中.
来自网站..
Jar Jar Links is a utility that makes it easy to repackage Java libraries and embed them into your own distribution. This is useful for two reasons:
You can easily ship a single jar file with no external dependencies.
You can avoid problems where your library depends on a specific version of a library, which may conflict with the dependencies of another library.
如果这是关于重新打包可执行 jar 的问题,请查找 One-Jar。此处讨论Easiest way to merge a release into one JAR file
关于 java |图书馆内部图书馆包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715862/