引用外部jar的JavaFx 2.0应用程序 [英] JavaFx 2.0 application referencing external jars

查看:172
本文介绍了引用外部jar的JavaFx 2.0应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans 7开发JavaFx 2.0应用程序. 主应用程序引用另一个右键单击库"文件夹并选择添加项目..."添加的类库项目.从netbeans执行应用程序工作正常.

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 selecting 'Add Project...'. Executing the application from netbeans works fine.

通过清理并构建"将其部署到jar文件中并尝试使用控制台通过

When deploying it to a jar file by 'Clean and build' and trying to execute it via console with

java -jar TestApp.jar

我知道

Exception in thread "JavaFX-Launcher" java.lang.NoClassDefFoundError: net/pmoule/SomeClass
...

我的应用程序的dist/lib文件夹包含引用的库.所以恕我直言,一切都应该很好.看看我的应用程序jar中包含的Manifest.MF,我明白了

The dist/lib folder of my application contains the referenced library. So IMHO everything should be fine. Looking at the Manifest.MF contained in my application jar I get this

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_23-b05 (Sun Microsystems Inc.)
Implementation-Vendor: pmoule
Implementation-Title: TestApp
Implementation-Version: 1.0
Main-Class: com/javafx/main/Main
JavaFX-Application-Class: testapp.TestApp
JavaFX-Version: 2.0

我的课程路径在哪里?如何让Netbeans添加正确的类路径?

Where is my class path? How do I get Netbeans to add the correct classpath?

我尝试通过编辑jar中包含的一个将其手动添加到Manifest.MF中.

I tried adding it manually to the Manifest.MF by editing the one contained in the jar

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_23-b05 (Sun Microsystems Inc.)
Implementation-Vendor: pmoule
Implementation-Title: TestApp
Implementation-Version: 1.0
Class-Path: lib/MyLib.jar        //THIS IS NEW
Main-Class: com/javafx/main/Main
JavaFX-Application-Class: testapp.TestApp
JavaFX-Version: 2.0

没有成功,也有同样的错误.

No success and same error.

JavaFX 2.0 SDK随附的所有示例都可以通过双击WindowsExplorer或从控制台中输入以下内容来工作:

All samples delivered with the JavaFX 2.0 SDK work by doubleclicking in WindowsExplorer or from the console by entering e.g.

java -jar PathAnimation.jar

但是这些示例中的任何一个都不引用外部jar.

But not any of these examples makes a reference to an external jar.

一些研究使我想到了这个问题: Netbeans JavaFX 2.0应用程序 但是到目前为止还没有任何解决办法.

Some research lead me to this question: Netbeans JavaFX 2.0 Application But without any solution so far.

感谢您的帮助!

推荐答案

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

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.

这篇关于引用外部jar的JavaFx 2.0应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆