我已經構建了一個JavaFX應用程序,該應用程序可以通過其jar文件執行。但是,如果我嘗試使用自帶的EXE捆綁我正在接收兩個彈出窗口來運行它:JavaFX應用程序無法使用本地EXE捆綁包啓動
COM/NPAP/dicomrouter /主 - 無主類
未能推出JVM
並且應用程序無法啓動。
這是我的主類(大多數部分):
package com.npap.dicomrouter;
public class Main extends Application {
...
public static void main(String[] args) throws IOException {
try {
JUnique.acquireLock(appId);
alreadyRunning = false;
log.info("application is going to start running!!!!");
} catch (AlreadyLockedException e) {
alreadyRunning = true;
log.info("application is already running!!!!");
}
if (!alreadyRunning) {
Application.launch(Main.class, (java.lang
.String[])null);
}
}
@Override
public void start(Stage primaryStage) throws IOException {
...
try {
AnchorPane page = (AnchorPane) FXMLLoader.load(Main.class.getResource("FXMLDocument.fxml"));
Scene scene = new Scene(page, initWidth, initHeight);
primaryStage.setScene(scene);
Platform.setImplicitExit(false);
createTrayIcon(primaryStage);
primaryStage.setTitle(appTitle);
primaryStage.show();
} catch (IOException ex) {
log.log(Level.INFO, null, ex);
}
}
我的build.xml配置是這樣的:
<target name="-post-jfx-deploy">
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
nativeBundles="all"
outdir="${basedir}/${dist.dir}" outfile="${application.title}">
<fx:application name="${application.title}"
mainClass="${javafx.main.class}"/>
<fx:resources>
<fx:fileset dir="${basedir}/${dist.dir}"
includes="*.jar"/>
</fx:resources>
<fx:info title="${application.title}"
vendor="${application.vendor}"/>
</fx:deploy>
</target>
我構建的應用程序(Java FX 2.1)使用Netbeans的,在這裏的方式描述:
https://netbeans.org/kb/docs/java/native_pkg.html
和IH ave用本機exe包成功構建和運行其他javafx應用程序。我還附上一張屏幕截圖,顯示我如何申報主項目的課程。
所以我深刻地認爲這是一個項目的具體問題。在控制檯中構建我得到:
The jar lib\hibernate-commons-annotations-4.0.2.Final.jar has a main class org.hibernate.annotations.common.Version that does not match the declared main com.xxxx.yyyy.Main
The jar lib\javassist-3.15.0-GA.jar has a main class javassist.CtClass that does not match the declared main com.xxxx.yyyy.Main
The jar lib\h2-1.3.176.jar has a main class org.h2.tools.Console that does not match the declared main com.xxxx.yyyy.Main
除了這些罐子,我使用含有「主」的方法(可運行)其他幾個班。
@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
...
其中大多數是第三方實用程序類。
我也在package.cfg文件的內容只是FYI:
app.mainjar=DicomRouterAffidea0_2_2.jar
app.version=1.0
app.id=com.npap.dicomrouter
app.preferences.id=com/npap/dicomrouter
app.mainclass=com/npap/dicomrouter/Main
app.classpath=lib/antlr-2.7.7.jar lib/c3p0-0.9.2.1.jar lib/clibwrapper_jiio.jar .....
... //jars listing
最後我附上圖書館3個截圖,編譯和部署Netbeans的配置。希望也能幫助:
這可能不是問題的原因,但我會強烈建議傳遞一個空數組,而不是null'的'你的時候調用'launch()'。 –
另外,它看起來像你的build.xml已經指定了主類,並將其解析爲屬性'$ {javafx.main.class}'。這個定義是否正確? –
感謝James_D的迴應......我試着用一個空數組進行試運行,但同樣的錯誤仍然存在。另外我編輯了我的文章,並附上了一張屏幕截圖,顯示我如何在項目參數中聲明我的Main類。我猜build.xml應該解決並加載這個屬性。我認爲它是正確定義的,因爲從jar工作正常工作正常。我會進一步檢查,替代build.xml配置... – thanili