2011-07-19 27 views
2

我正在開發一個使用Netbeans 7的JavaFx 2.0應用程序。 主應用程序引用通過右鍵單擊'Libraries'文件夾並選擇'Add Project ...'添加的另一個類庫項目。從netbeans執行應用程序工作正常。引用外部jar的JavaFx 2.0應用程序

當「清潔和建設」部署到一個jar文件,並試圖通過控制檯

java -jar TestApp.jar 

執行它,我得到

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

我的應用程序下的dist/lib文件夾中包含引用的庫。所以恕我直言一切應該沒問題。看看我的應用程序jar包含的Manifest.MF我得到這個

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添加正確的類路徑?

我試圖通過編輯包含在罐子

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 

沒有成功,同樣的錯誤了一個手動添加它到的Manifest.MF。

通過在WindowsExplorer中雙擊或從控制檯輸入例如JavaFX 2.0 SDK,所有樣本都可以工作。

java -jar PathAnimation.jar 

但是沒有任何這些例子會引用外部jar。

有些研究讓我想到這個問題:Netbeans JavaFX 2.0 Application 但是目前爲止還沒有任何解決方案。

感謝您的幫助!

+0

更新:爲了滿足[Oracle](http://download.oracle.com/javafx/2.0/system_requirements/jfxpub-system_requirements.htm)中列出的要求,我將平臺更改爲JDK 6_26;我將這一行添加到項目的jfx-impl.xml''中的fxjar-task。現在類路徑包含在manifest.mf中。錯誤仍然是: – pmoule

回答

3

自己找到了一個工作解決方案。

dist/lin文件夾中的所有外部庫的大小都爲0kb。所以當然,例外是正確的。

爲了讓我的應用程序運行時我做了該項目的JFX-impl.xml中的以下內容:

添加classpath中體現。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資源管理器或通過輸入

java -jar TestApp.jar 

我新創建的web-dir的內容仍然存在一些問題。

  1. 的TestApp.jar北京時間不會複製ZO DIST /網絡
  2. 引用的外部罐子不會被複制到dist/WEB

這是爲我好,並會在稍後修正了一些時間。

希望這可以幫助其他人。

0

在Netbeans中,在project => properties => Build => Packaging下,是否勾選了「Copy Dependent Libraries」?

+0

感謝您的提示,選項被選中。正如我寫的,項目的dist/lib文件夾在執行「Clean and Build」之後包含有問題的庫。 – pmoule

+0

您是否按照以下說明進行操作FXDeployment?http://download.oracle.com/javafx/2.0/deployment/jfxpub-deployment.pdf – JimClarke

+0

是的,我遵循部署指南中的指導,我甚至更新了JavaFX的Netbeans插件並更新了項目的構建文件。沒有任何外部jar的部署工作正常。只有在包含一些外部jar時纔會出現問題。 – pmoule

0

你需要告訴FX:jar任務的路徑依賴是什麼:

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

你還需要使用外匯:資源標籤在你的外匯:而不是部署只是資源的任務。這應該可以解決您答案中留下的最後兩個問題。

相關問題