问题描述
使用JDA 4.2.0的新更新尝试在VPS上运行jar文件失败。 我尝试了各种选择,例如
- creating a fat jar
- 寻找其他类似问题
但是,由于VPS控制台输出保持不变,因此这些选项似乎都不起作用:
Error: Could not find or load main class ...
Caused by: java.lang.NoClassDefFoundError: net/dv8tion/jda/api/hooks/ListenerAdapter
所以我当前的问题是,我的gradle.build
应该是什么样子,还是VPS无法正确刷新的问题?也许还有另一个我不知道的问题。
关于我的gradle.build
是什么样的:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
group '...'
version '2.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter(
)
}
dependencies {
testCompile group: 'junit',name: 'junit',version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_168'
compile group: 'commons-collections',name: 'commons-collections',version: '3.2'
compile group: 'MysqL',name: 'mysql-connector-java',version: '8.0.20'
compile group: 'javax.persistence',name: 'persistence-api',version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
jar {
manifest {
attributes(
'Main-Class': '...'
)
}
}
注意:在1.0-SNAPSHOT
的上一个快照中,接下来的gradle.build
用来启动项目:
plugins {
id 'java'
id 'application'
}
group '...'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit',version: '4.+'
compile 'net.dv8tion:JDA:3.5.0_329'
compile group: 'commons-collections',version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
解决方法
您可以使用此build.gradle
来建立一个有效的影子罐:
plugins {
id 'application' // this allows you to set a mainClassName
id 'com.github.johnrengelman.shadow' version '6.0.0' // this adds the shadowJar task
}
group '...'
version '2.0-SNAPSHOT'
mainClassName = 'your main class goes here' // this sets the main class property in your manifest automatically
repositories {
jcenter() // jcenter is a superset of mavenCentral
}
dependencies {
testCompile group: 'junit',name: 'junit',version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_191'
compile group: 'commons-collections',name: 'commons-collections',version: '3.2'
compile group: 'mysql',name: 'mysql-connector-java',version: '8.0.20'
compile group: 'javax.persistence',name: 'persistence-api',version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
运行shadowJar
gradle任务来编译jar文件。然后将其放置在build/libs
内,格式为[name]-all.jar
。别忘了用您的主类的完全限定名称替换mainClassName
。