在javafx应用程序中使用maven ant插件,如何在javaFX jar中添加依赖项.仍面临类未找到异常 [英] Using maven ant plugin in javafx application, How to add Dependencies in javaFX jar. Still facing class not found exception
问题描述
我使用本指南将我的依赖项添加到主jar 捆绑了依赖项的JavaFX jar 我面临着导致类未找到异常的依赖关系问题.我的Pom就像上面链接中提到的一样.我使用依赖项插件将依赖项复制到目标中的lib文件夹.
I using this guide added my dependencies to main jar JavaFX jar with dependencies bundled i am facing dependencies issue which causing Class not found exception. My Pom is exactly like mentioned in above link. i use dependencies plugin to copy dependencies to lib folder in target.
这是我的堆栈跟踪
Try calling Class.forName(com.client.main.App) using classLoader = j
ava.net.URLClassLoader@3c9076d
found class: class com.client.main.App
launchApp: Try calling com.sun.javafx.application.LauncherImpl.launchApplication
Autoconfig of proxy is completed.
JavaFX: using com.sun.javafx.tk.quantum.QuantumToolkit
Exception in Application init method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.javafx.main.Main.launchApp(Main.java:698)
at com.javafx.main.Main.main(Main.java:871)
Caused by: java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown So
urce)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Module
at com.nuaxis.rpas.client.main.App.init(App.java:25)
... 4 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
Done with invoke and wait
使用maven ant插件在maven pom文件中的Maven Ant任务
Maven Ant Task in maven pom file using maven ant plugin
<jfxjar destfile="${project.build.directory}/${project.build.finalName}">
<fileset dir="${project.build.directory}/classes" />
<fileset dir="${project.build.directory}/lib/" includes="*.jar" />
<application name="${project.name}" mainClass="com.client.main.App" />
<resources>
<fileset dir="${project.build.directory}/lib/" includes="*.jar" />
</resources>
</jfxjar>
这是我的Fx应用程序类代码
Here is my Fx Application Class code
public class App extends Application {
/*public static Logger mLogger = LoggerFactory.getLogger(App.class); */
public static Injector injector;
public static AppHandler mAppHandler;
@Override
public void init() throws Exception {
// TODO Auto-generated method stub
super.init();
injector = Guice.createInjector(new GuiceModule());/*This line cause exception*/
mAppHandler = injector.getInstance(AppHandler.class);
if(mAppHandler!=null)
mAppHandler.startHandler();
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/FXMLDocument.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/style.css");
stage.setTitle("RPAS Java Client");
stage.getIcons().add(new Image("/images/RPAS Java Client.png"));
stage.setScene(scene);
stage.show();
}
@Override
public void stop() throws Exception {
mAppHandler.stopHandler();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
这是我的理解
现在我了解的是我的依赖项未正确加载.蚂蚁的罐子制作"任务使得罐子没有任何问题.当我双击通过异常.我打开了罐子,这是我的清单
Now what i understand is my dependencies are not properly loading. ant "jar making" task makes jar without any issues. when i double click it through exception. I opened the jar and here is my Manifest
Manifest-Version: 1.0
JavaFX-Version: 2.2
JavaFX-Application-Class: com.client.main.App
JavaFX-Class-Path: guice-3.0.jar hamcrest-core-1.3.jar javax.inject-1.jar log4j-1.2.15.jar slf4j-api-1.7.7.jar slf4j-log4j12-1.7.7.jar
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main
我还想知道我何时看到jar制作过程将com.javafx.main.Main.java文件自动添加到代码中,该文件首先检查运行时(JRE和FX),然后是否全部成功调用com.sun.javafx .Application.LauncherImp.
I also wonder when i saw that jar making process add com.javafx.main.Main.java file to the code automatically which first check Run time(JRE and FX) and then if all successful invoke the com.sun.javafx.Application.LauncherImp .
有人可以帮助我吗?
推荐答案
I had resolved the issue. see my final pom at this link where should i put installer resources (wxs file,dmg-script,icon) and how to configure maven antrun when deploying self contained app
这篇关于在javafx应用程序中使用maven ant插件,如何在javaFX jar中添加依赖项.仍面临类未找到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!