我知道这个问题被问了很多并且有很多答案,但我仍然明白,但我不明白为什么......
我正在尝试生成一个.jar
来自与 gradle 具有依赖关系的项目。
我有课src/main/java/Launcher.java
,其中我有我的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) }
}
}
I use $>gradle assemble
生成我的罐子
然后$>java -jar path/to/my/.jar
我收到错误“无法找到或加载主类启动器”...
我不明白为什么当我查看 .jar 时,我有 Launcher 类,而在 META-INF 中我有我的清单
很抱歉在 2018 年仍然问这个问题,但我正在失去理智试图找出问题所在。我希望有人能给出答案!
我在本地重现了您的问题。
只需添加exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
到 jar 任务。
这将排除干扰依赖项的签名。
Example:
jar {
manifest {
attributes "Main-Class": mainClassName
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)