Executable jar can't find or load main class after it's created with a gradle task

前端 未结 1 2026
南笙
南笙 2021-01-23 22:34

I used the gluon plugin to create a new single view project and changed nothing in its files. If I use the gradle task application > run it works fine. But if I

相关标签:
1条回答
  • 2021-01-23 23:20

    When you execute the jar task on a Gluon project, you will get just a jar with the classes and resources under the main and desktop packages of your project. In your case, something like this:

    That jar contains the main class, but it doesn't contain any of the dependencies (Gluon Charm).

    If you want to create an executable jar, you need to create a shadowJar or fatJar, that bundles all the dependencies within that jar.

    You can add this plugin for it: com.github.johnrengelman.shadow, based on this project.

    Once you add the plugin, all you need to do is let it know about your custom configurations, as it doesn't know about the Desktop one.

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
            classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
        }
    }
    
    apply plugin: 'org.javafxports.jfxmobile'
    apply plugin: 'com.github.johnrengelman.shadow'
    
    ...
    
    // Add desktop dependencies to the task
    shadowJar {
        configurations = [project.configurations.desktopRuntime]
    }
    

    Reload your project and execute shadowJar. You can find it under the Tasks menu:

    You will find your executable jar under /builds/libs/yourProjectName-all.jar.

    0 讨论(0)
提交回复
热议问题