我使用本指南将我的依赖项添加到捆绑了依赖项的主 jar JavaFX jar 我面临导致找不到类异常的依赖项问题。我的 Pom 与上面链接中提到的完全一样。我使用依赖项插件将依赖项复制到目标中的 lib 文件夹。
这是我的堆栈跟踪
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 任务
<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 应用程序类代码
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);
}
}
这是我的理解
现在我明白我的依赖项没有正确加载。ant“罐子制作”任务使罐子没有任何问题。当我通过异常双击它时。我打开罐子,这是我的清单
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。启动器Imp 。
有谁能够帮我?