Gradle - FatJar - 无法找到或加载主类 [英] Gradle - FatJar - Could not find or load main class

查看:511
本文介绍了Gradle - FatJar - 无法找到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题被问了很多并且有很多答案,但我仍然明白了,我不明白为什么......

I know that question was asked a lot and has many answers, but i still get it and I don't understand why...

我正在努力从具有gradle依赖项的项目中生成 .jar

I am trying to generate a .jar from a projet with dependencies with gradle.

我有一个类 src / main / java / Launcher.java ,其中我有 main 方法。

I have a class src/main/java/Launcher.java, in which I have my main method.

我的 build.gradle

plugins {
    id 'java'
    id 'application'
}

version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = 'Launcher'

repositories {
    mavenCentral()
}

dependencies {
    compile 'commons-io:commons-io:2.1'
    compile 'io.vertx:vertx-core:3.4.0'
    compile 'io.vertx:vertx-web:3.4.0'
    compile 'com.google.code.gson:gson:1.7.2'
    compile "com.auth0:java-jwt:3.1.0"
    compile 'org.mongodb:mongo-java-driver:3.4.1'
    compile 'com.google.guava:guava:24.1-jre'
    compile 'commons-io:commons-io:2.6'
}

jar {
    manifest {
        attributes "Main-Class": mainClassName
    }

    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

我用 $> gradle assemble 生成我的jar
然后 $> java -jar path / to / my / .jar
我得到错误无法找到或加载主类Launcher...

I use $>gradle assemble to generate my jar then $>java -jar path/to/my/.jar And i get the error "could not find or load main class Launcher"...

我不明白为什么,当我查看。 jar,我有Launcher类,在META-INF我有我的清单

I dont understand why, when I look in the .jar, I have Launcher class and in META-INF I have my manifest

很抱歉在2018年仍然提出这个问题,但我想弄清楚我的想法是什么问题。我希望somone能得到答案!

Sorry for still asking this question in 2018 but i'm loosing my mind trying to figure out what's wrong. I hope somone will have the answer !

推荐答案

我在本地转载了你的问题。

I reproduced your issue locally.

只需添加排除'META-INF / * .RSA','META-INF / *。SF','META-INF / * .DSA'到jar任务。

Just add exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' to the jar task.

这将排除干扰依赖关系的签名。

This will exclude the signatures of interfering dependencies.

这篇关于Gradle - FatJar - 无法找到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆