简体   繁体   English

Java Netbeans,库在构建时未打包到jar文件中

[英]Java Netbeans, libraries not being packaged into jar file on build

I am using netbeans and have this in my build.xml file (under Project > Build.xml) 我正在使用netbeans,并将其保存在我的build.xml文件中(在“项目”>“ Build.xml”下)

<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="MyProjectName"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>

<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
    <zipgroupfileset dir="dist" includes="*.jar"/>
    <zipgroupfileset dir="dist/lib" includes="*.jar"/>
    <manifest>
        <attribute name="Main-Class" value="${main.class}"/>
    </manifest>
</jar>

<zip destfile="${store.jar}">
    <zipfileset src="${store.dir}/temp_final.jar"
    excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>

<delete file="${store.dir}/temp_final.jar"/>

Supposedly what this should do is package the 3 libraries i have into my jar file so that when the jar is run it has its dependencies with it. 大概应该做的是将我拥有的3个库打包到我的jar文件中,以便在运行jar时具有它的依赖关系。

My folder system looks like this: 我的文件夹系统如下所示:

Project / dist / lib / 项目/ dist / lib /

  • commons-lang3-3-7.jar commons-lang3-3-7.jar
  • commons-text-1.1.jar commons-text-1.1.jar
  • jsoup-1.10.3.jar jsoup-1.10.3.jar

But when i click "Clean and Build" in netbeans it does not package the libraries into the jar, instead it seems to be ignoring the code that i have put in the build.xml file. 但是,当我在netbeans中单击“清理并生成”时,它没有将库打包到jar中,而是似乎忽略了我放入build.xml文件中的代码。

Is there some button that i need to click in order to get it to use my build configuration? 我需要单击一些按钮以使其使用我的构建配置吗?

Finally i found the answer. 终于我找到了答案。 In Netbeans it is possible to build the dependent libraries within the jar file. 在Netbeans中,可以在jar文件中构建依赖库。

Netbeans features a tool that automatically un-archives the dependent libraries and includes them in the jar (such as MyJar.jar|org\\apache\\commons...). Netbeans提供了一种工具,该工具可以自动取消存档依赖库并将其包含在jar中(例如MyJar.jar | org \\ apache \\ commons ...)。

And it is actually very easy to do! 而且实际上很容易做到!

  • First you need to click on the "Files" tab in the top left window which shows your project. 首先,您需要单击显示您的项目的左上角窗口中的“文件”选项卡。 Then you should be able to see all your files including the Build.xml (in which you have put your build code, such as that featured in the question above). 然后,您应该能够看到所有文件,包括Build.xml(已在其中放置了构建代码,例如上面的问题中的内容)。

  • Right click on the Build.xml file and select "Run Target" 右键单击Build.xml文件,然后选择“运行目标”

  • Then choose "Other Target" in the pop up menu 然后在弹出菜单中选择“其他目标”

  • Then select "package-for-store" in the further pop up menu 然后在另一个弹出菜单中选择“商店包装”

This will then build your jar file, with dependencies under /YourProject/store/ 然后,这将构建您的jar文件,其依赖项位于/ YourProject / store /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM