如何从胶子项目中导出.jar文件?

时间:2017-11-26 17:34:02

标签: javafx gluon gluon-mobile javafxports

任何想法如何导出包含胶子项目中的所有内容的.jar? 我使用了Shadow jar但结果不会打开并给出

    Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter
        at com.gluonhq.charm.glisten.control.AppBar.<clinit>(SourceFile:406)
        at com.gluonhq.charm.glisten.application.MobileApplication.start(SourceFile:191)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.SizeConverter
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 11 more

1 个答案:

答案 0 :(得分:0)

要导出一个Gluon项目的jar以便它在桌面上运行,您可以使用此plugin中的Shadow answer,或者您可以使用内置任务jar或者'distZip,但考虑到您需要修改构建以包含桌面依赖项,如here

之后,生成的jar将根据您使用的依赖项在Java 8或Java 9上运行。

到目前为止,常规的jfxmobile插件使用Java 8的依赖项:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.9'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

dependencies {
    compile 'com.gluonhq:charm:4.4.1'
}

因此生成的jar只能在Java 8下运行。

但您可以修改构建,以便在桌面上运行Java 9:

dependencies {
    compile 'com.gluonhq:charm:4.4.0-jdk9'
}

请注意,如果您有其他依赖项,那么它们也应与Java 9兼容。