且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

引用外部jar的JavaFx 2.0应用程序

更新时间:2023-01-26 11:59:47

我自己找到了可行的解决方案.

Found a working solution by myself.

dist/lin文件夹中的所有外部库的大小均为0kb.因此,当然是正确的例外.

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

要使我的应用程序运行,我在项目的jfx-impl.xml中执行了以下操作:

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

将类路径添加到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>

创建用于Web部署的输出目录

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

设置fxdeploy任务的输出目录

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

现在,我可以部署桌面应用程序并通过Windows资源管理器中的双击或输入来执行ist.

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

java -jar TestApp.jar

我新创建的Web目录的内容仍然存在一些问题.

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

  1. TestApp.jar ist未复制zo dist/web
  2. 引用的外部jar不会复制到dist/web

这对我来说很好,稍后会修复.

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

希望这对其他人有帮助.

Hope this helps anyone else.