JavaFX 应用程序无法使用本机 exe 包启动
JavaFX application fail to launch with native exe bundle
我构建了一个 JavaFX 应用程序,可以通过其 jar 文件执行。但是,如果我尝试使用本机 exe 包 运行 它,我会收到两个弹出窗口:
com/npap/dicomrouter/Main - 无主class
未能启动 JVM
应用程序无法启动。
这是我的主class(大部分):
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>
我正在使用 Netbeans 构建应用程序 (Java FX 2.1),方法如下:
https://netbeans.org/kb/docs/java/native_pkg.html
并且我已经成功构建和 运行 其他带有本机 exe 包的 javafx 应用程序。我还附上了一张屏幕截图,显示了我如何声明主项目的 class.
所以我深深地认为这是一个特定于项目的问题。在控制台构建期间,我得到:
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
除了这些罐子之外,我还使用其他几个包含 "main" 方法的 classes(运行nable)。
@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
...
其中大部分是第 3 方实用程序 classes.
我还添加了 package.cfg 文件的内容,仅供参考:
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
最后,我附上了库、编译和部署 Netbeans 配置的 3 个屏幕截图。希望也能有所帮助:
只是回答我的问题,因为经过一些试验,我设法通过从 build.xml.
中删除代码来构建一个功能性 .exe 文件
所以我从 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>
我正在导入:
<import file="nbproject/build-impl.xml"/>
我构建了一个 JavaFX 应用程序,可以通过其 jar 文件执行。但是,如果我尝试使用本机 exe 包 运行 它,我会收到两个弹出窗口:
com/npap/dicomrouter/Main - 无主class
未能启动 JVM
应用程序无法启动。
这是我的主class(大部分):
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>
我正在使用 Netbeans 构建应用程序 (Java FX 2.1),方法如下:
https://netbeans.org/kb/docs/java/native_pkg.html
并且我已经成功构建和 运行 其他带有本机 exe 包的 javafx 应用程序。我还附上了一张屏幕截图,显示了我如何声明主项目的 class.
所以我深深地认为这是一个特定于项目的问题。在控制台构建期间,我得到:
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
除了这些罐子之外,我还使用其他几个包含 "main" 方法的 classes(运行nable)。
@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
...
其中大部分是第 3 方实用程序 classes.
我还添加了 package.cfg 文件的内容,仅供参考:
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
最后,我附上了库、编译和部署 Netbeans 配置的 3 个屏幕截图。希望也能有所帮助:
只是回答我的问题,因为经过一些试验,我设法通过从 build.xml.
中删除代码来构建一个功能性 .exe 文件所以我从 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>
我正在导入:
<import file="nbproject/build-impl.xml"/>