从javaFX项目获取带有依赖项的jar文件

时间:2013-02-17 16:15:29

标签: javafx-2 javafx netbeans-7

我正在尝试使用此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启动器收到错误消息:

无法找到应用程序类名称。

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

1 个答案:

答案 0 :(得分: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,并查看这些字段的清单中的内容。