将 java 库包含到自己的库中 [英] Include java libraries into own library
问题描述
我为自己创建了一个小框架,我想在多个项目中使用它.我还希望分布式 jar 文件包含所有外部库,以便我的项目只需要包含我的库即可访问所有外部库.
I created a little framework for myself which I want to use in multiple projects. I also want the distributed jar-file to include all external libraries so that my projects just need to include my library to access all external libraries.
我需要这个来简化外部库的更新.
I need this to simplify updating the external libraries.
所以我把它放在我的 build.xml 中,它将 dist/lib 中的所有库添加到我自己的 jar 文件中.
So I placed this in my build.xml which adds all libraries from dist/lib into my own jar-file.
<target name="-post-jar">
<!-- Include all java libraries -->
<fileset dir="dist/lib" id="extern.libs">
<include name="*.jar" />
</fileset>
<!-- Add the libraries from the fileset to the project.jar -->
<jar jarfile="${dist.jar}" update="true">
<zipgroupfileset refid="extern.libs"/>
</jar>
</target>
但是当我尝试使用诸如org.zkoss.zk.ui.Component"之类的外部库时,我收到无法找到该库的错误.
But when I try to use external libraries like "org.zkoss.zk.ui.Component" I get the error that this library could not be found.
是否有更好的方法将外部库包含到我自己的库中,以便我的项目可以使用它们?
Is there a better way to include the external libraries into my own library so that my project can use them?
推荐答案
您可以发布一个 Maven 工件,其中然后框架的用户可以使用,而不必自己包含依赖项——你的 pom 就足够了.
You can publish a Maven artifact, which users of your framework can then use without having to include the dependencies yourself--your pom is enough.
如果您想创建一个多合一"工件,请考虑OneJar或 jarjar 或 Maven 的 Shade plugin 来创建一个没有外部依赖的 jar.
If you want to create an "all-in-one" artifact, consider something like OneJar or jarjar or Maven's Shade plugin to create a jar that has no external dependencies.
这篇关于将 java 库包含到自己的库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!