【问题标题】:create executable jar including external jar file from Netbeans 8.0.2 and java 8从 Netbeans 8.0.2 和 java 8 创建包括外部 jar 文件的可执行 jar
【发布时间】:2020-03-02 08:05:08
【问题描述】:

我想创建包含我的外部 jar 文件的可执行 jar 文件, 我正在使用 Netbeans 8.0.2 和 Java 8 我尝试使用互联网和 stackoverflow 上提供的解决方案更新 build.xml, 但是外部 jars 文件没有包含在我的单个可执行 jar 文件中。 这个我也试过了

<target name="package-for-store" depends="jar">
    <property name="store.jar.name" value="myProject"/>
    <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"/>
</target>

我也试过了

How to build a fat jar using Netbeans

它创建了一个 jar 文件,但它不包含我的外部依赖项。 谁能帮助我如何使用 Netbeans 8.0.2java8 将我的外部 jar 包含到单个可执行 jar 中

【问题讨论】:

    标签: java-8 netbeans-8


    【解决方案1】:

    我终于找到了答案, 我在 build.xml 中使用了以下配置

    <target name="package-for-store" depends="jar">
        <property name="store.jar.name" value="DocumentProtector"/>
        <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} mainclass ${main.class}"/>
        <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"/>
    </target>
    

    clean+build之后 右键单击build.xml 并转到Other target 并单击package-for-store 但是在这样做之后我弄错了主课 所以经过一番研究,我找到了改变主类的解决方案 转到project folder -&gt; nbproject and open project.properties 文件 并将 main.class 更改为带有包名的邮件类文件名 像这样main.class=com.test.package.MainClassclean+build 并再次 右键单击build.xml 并转到Other target 并单击package-for-store

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-16
      • 2014-12-31
      • 2020-04-17
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 2012-06-13
      相关资源
      最近更新 更多