0

我正在尝试使用此 build.xml (NetBeans) 构建具有依赖关系的 jar 文件:

<?xml version="1.0" encoding="UTF-8"?><!-- You may freely edit this file. See commented blocks below for --><!-- some examples of how to customize the build. --><!-- (If you delete it and reopen the project it will be recreated.) --><!-- By default, only the Clean and Build commands use this build script. --><project name="TargetAppDesktop" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <description>Builds, tests, and runs the project TargetAppDesktop.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. Those of them relevant for JavaFX project are: 

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-jfx-jar:              called before FX SDK specific <fx:jar> task
      -post-jfx-jar:             called after FX SDK specific <fx:jar> task
      -pre-jfx-deploy:           called before FX SDK specific <fx:deploy> task
      -post-jfx-deploy:          called after FX SDK specific <fx:deploy> task
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting a HTML postprocessor after javaFX SDK deployment:

        <target name="-post-jfx-deploy">
            <basename property="jfx.deployment.base" file="${jfx.deployment.jar}" suffix=".jar"/>
            <property name="jfx.deployment.html" location="${jfx.deployment.dir}${file.separator}${jfx.deployment.base}.html"/>
            <custompostprocess>
                <fileset dir="${jfx.deployment.html}"/>
            </custompostprocess>
        </target>

    Example of calling an Ant task from JavaFX SDK. Note that access to JavaFX SDK Ant tasks must be
    initialized; to ensure this is done add the dependence on -check-jfx-sdk-version target:

        <target name="-post-jfx-jar" depends="-check-jfx-sdk-version">
            <echo message="Calling jar task from JavaFX SDK"/>
            <fx:jar ...>
                ...
            </fx:jar>
        </target>

    For more details about JavaFX SDK Ant tasks go to
    http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm

    For list of available properties check the files
    nbproject/build-impl.xml and nbproject/jfx-impl.xml.

    -->

<!--   Para  gerar um arquivo unico adicionar as linhas abaixo -->

    <target name="package-for-store" depends="jar">

        <!-- Change the value of this property to be the name of your JAR,
             minus the .jar extension. It should not have spaces.
             <property name="store.jar.name" value="MyJarName"/>
        -->
        <property name="store.jar.name" value="TargetAppDesktop"/>


        <!-- don't edit below this line -->

        <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>


    <!--> Fim do codigo para arquivo unico -->
</project>

当我构建它时,一切似乎都很好,但是当我尝试打开我的 jar 文件时,我从 javaFX 启动器收到错误消息:

找不到应用程序类名称。

有人知道发生了什么吗?或者更简单的方法来获得这个罐子?

4

1 回答 1

0

您将需要稍微更改清单。从你所拥有的:

<manifest>
     <attribute name="Main-Class" value="${main.class}"/>
</manifest>

类似于:

 <manifest>
              <attribute name="Main-Class" value="${main.class}"/>
<!-- your javaFX version -->
              <attribute name="JavaFX-Version" value="2.2"/>
<!-- your main class -->
              <attribute name="JavaFX-Application-Class" value="package.MainClass"/>
<!-- your javaFx build path -->
              <attribute name="JavaFX-Class-Path" value="lib/Program.jar lib/Utils.jar lib/commons-codec-1.5
     .jar lib/commons-logging-1.1.jar lib/dom4j-1.6.1.jar lib/junit-4.10.j
     ar lib/poi-3.10-FINAL-20140208.jar lib/poi-excelant-3.10-FINAL-201402
     08.jar lib/poi-ooxml-3.10-FINAL-20140208.jar lib/poi-ooxml-schemas-3.
     10-FINAL-20140208.jar lib/poi-scratchpad-3.10-FINAL-20140208.jar lib/
     stax-api-1.0.1.jar lib/xmlbeans-2.3.0.jar"/>
             <attribute name="Permissions" value="sandbox"/>

    </manifest>

我个人使用了上面的那个并且它有效,但是正如你所看到的,它具有我的项目所独有的东西。获取 javaFX 路径和版本的最简单方法是使用 7zip 或类似程序打开 dist 文件夹中的 jar,然后查看这些字段的清单中的内容。

于 2014-11-17T20:47:52.760 回答