JavaFX应用程序无法使用本机exe包启动 [英] JavaFX application fail to launch with native exe bundle
问题描述
我已经构建了一个可以通过其jar文件执行的JavaFX应用程序。但是,如果我尝试使用本机exe包运行它,我将收到两个弹出窗口:
-
com / npap / dicomrouter / Main - 没有主要课程
-
无法启动JVM
并且应用程序无法启动。
这是我的Main类(大部分内容):
package com.npap.dicomrouter;
公共类Main扩展Application {
...
public static void main(String [] args)抛出IOException {
try {
JUnique.acquireLock(appId);
alreadyRunning = false;
log.info(应用程序将开始运行!!!!);
} catch(AlreadyLockedException e){
alreadyRunning = true;
log.info(应用程序已在运行!!!!);
}
if(!alreadyRunning){
Application.launch(Main.class,(java.lang
.String [])null);
}
}
@Override
public void start(Stage primaryStage)抛出IOException {
...
try {
AnchorPane page =(AnchorPane)FXMLLoader.load(Main.class.getResource(FXMLDocument.fxml));
场景场景=新场景(页面,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),其方式如下:
所以我深刻地认为这是一个项目特定的问题。在控制台中构建期间,我得到:
jar lib \hibernate-commons-annotations-4.0.2.Final。 jar有一个主类org.hibernate.annotations.common.Version,它与声明的主com.xxxx.yyyy.Main
不匹配jar lib\javassist-3.15.0-GA.jar有一个主类javassist.CtClass与声明的主com.xxxx.yyyy.Main
不匹配jar lib\h2-1.3.176.jar有一个主类org.h2.tools.Console与声明的不匹配main com.xxxx.yyyy.Main
除了这些罐子外,我还使用其他几个包含 main方法(可运行)。
@SuppressWarnings(unchecked)
public static void main(String args [])抛出异常{
...
其中大多数是第三方派对实用程序类。
我也正在添加package.cfg文件的内容,仅供参考:
app.mainjar = DicomRouterAffidea0_2_2.ja r
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个Libraries,Compiling and Deployment Netbeans配置的截图。希望也可以提供帮助:
回答我的问题,因为经过一些试验,我设法通过从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/>
I have build a JavaFX application which can be executed by its jar file. However if i try to run it using the native exe bundle i am receiving two popups:
com/npap/dicomrouter/Main - no main class
failed to launch JVM
and the application fails to start.
This is my Main class (most of its part):
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);
}
}
My build.xml is configured this way:
<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>
I am building the application (Java FX 2.1) using Netbeans, in the way described here:
https://netbeans.org/kb/docs/java/native_pkg.html
and i have succesfully build and run other javafx applications with native exe bundle. I am also attaching a screenshot showing how i declare the main project's class.
So i profoundly assume that this is a project specific issue. During the build in the console i get:
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
Apart from these jars, i use several other classes which contain "main" methods (are runnable).
@SuppressWarnings("unchecked")
public static void main(String args[]) throws Exception {
...
Most of them are 3-rd party utility classes.
I am also adding the contents of package.cfg file just 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
Finally i am attaching 3 screenshots of Libraries, Compiling and Deployment Netbeans configuration. Hope that can also help:
Just answering my question since after some trials i managed to build a functional .exe file by removing the code from build.xml.
So i removed all these lines from 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>
and i am just importing:
<import file="nbproject/build-impl.xml"/>
这篇关于JavaFX应用程序无法使用本机exe包启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!