JavaFx 2.0 application referencing external jars

前端 未结 3 1253
耶瑟儿~
耶瑟儿~ 2020-12-20 04:04

I\'m developing a JavaFx 2.0 application using Netbeans 7. The main application references another class library project added by rightclicking the \'Libraries\' folder and

相关标签:
3条回答
  • 2020-12-20 04:06

    You need to tell the fx:jar task what your classpath dependencies are:

    <fxjar destfile="${jfx.deployment.dir}/${jfx.deployment.jar}" applicationClass="${main.class}" >
          <fileset dir="${build.classes.dir}"/>
          <manifest>
            <attribute name="Implementation-Vendor" value="${application.vendor}"/>
            <attribute name="Implementation-Title" value="${application.title}"/>
            <attribute name="Implementation-Version" value="1.0"/>
          </manifest>
    
          <!-- Setup the classpath for the generated .jar here -->
          <fx:resources>
            <fx:fileset type="jar" dir="lib" includes="MyLib.jar"/>
          </fx:resources>
    </fxjar>
    

    You also need to use fx:resources tag in your fx:deploy task instead of just resources. That should resolve the last two problems left in your answer.

    0 讨论(0)
  • 2020-12-20 04:22

    In Netbeans, under project => properties => Build => Packaging, did you check "Copy Dependent Libraries" ?

    0 讨论(0)
  • 2020-12-20 04:28

    Found a working solution by myself.

    All the external libraries in the dist/lin folder had a size of 0kb. So the exception was correct, of course.

    To get my application running I did the following in the project's jfx-impl.xml:

    Add the classpath to manifest.mf

    <fxjar destfile="${jfx.deployment.dir}/${jfx.deployment.jar}" applicationClass="${main.class}" >
                 <fileset dir="${build.classes.dir}"/>
                  <manifest>
                   <attribute name="Implementation-Vendor" value="${application.vendor}"/>
                   <attribute name="Implementation-Title" value="${application.title}"/>
    <!-- NEW -->   <attribute name="Class-Path" value="${jar.classpath}"/> <!-- NEW -->
                   <attribute name="Implementation-Version" value="1.0"/>
                  </manifest>
        </fxjar>
    

    Create an output dir for web deployment

    <property name="jfx.deployment.web.dir" location="${jfx.deployment.dir}/web" />
    <mkdir dir="${jfx.deployment.web.dir}" />
    

    Set output dir for fxdeploy task

    <fxdeploy width="${jfx.applet.width}" height="${jfx.applet.height}"
                  outdir="${jfx.deployment.web.dir}" <!-- NEW DIR -->
                  embedJNLP="true"
                  outfile="${application.title}">
            <info title="${application.title}"
                  vendor="${application.vendor}"/>
            <application name="${application.title}"
                         appclass="${main.class}"/>
            <resources type="eager">
               <fileset dir="${jfx.deployment.web.dir}"> <!-- NEW DIR -->
                  <include name="${jfx.deployment.jar}"/>
                  <include name="lib/*.jar"/>
                  <exclude name="**/jfxrt.jar"/>
               </fileset>
            </resources>
    </fxdeploy>
    

    Now, I can deploy my desktop application and execute ist via doubleclick from windows explorer or by entering

    java -jar TestApp.jar
    

    There still exists some issue with the content of my newly created web-dir.

    1. The TestApp.jar ist not copied zo dist/web
    2. The referenced external jars are not copied to dist/web

    This is fine for me and will be fixed some time later.

    Hope this helps anyone else.

    0 讨论(0)
提交回复
热议问题