0

With the new update of JDA 4.2.0 trying to run the jar file on the VPS fails. I have tried various options, such as

Yet none of these options seemed to work, since the VPS console output stays unchanged:

Error: Could not find or load main class ...
Caused by: java.lang.NoClassDefFoundError: net/dv8tion/jda/api/hooks/ListenerAdapter

So my current question is, what should my gradle.build look like, or is this a problem of the VPS not refreshing correctly? Or perhaps another problem I'm not aware of.

As for what my gradle.build looks like:

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': '...'
        )
    }
}

NOTE: In the previous snapshot of 1.0-SNAPSHOT this following gradle.build worked to start up the project:

plugins {
    id 'java'
    id 'application'
}

group '...'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.+'
    compile 'net.dv8tion:JDA:3.5.0_329'
    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'
}
King Reload
  • 2,780
  • 1
  • 17
  • 42

1 Answers1

2

You can use this build.gradle to build a working shadow jar:

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'
}

Run the shadowJar gradle task to compile your jar file. This will then be placed inside build/libs and has the format [name]-all.jar. Do not forget to replace the mainClassName with the fully qualified name of your main class.

Minn
  • 5,688
  • 2
  • 15
  • 42
  • Hello Minn, I tried your method, yet I don't fully understand what you mean with "Run the shadowJar gradle task to compile your jar file." as I am not familiar with shadowJar. – King Reload Aug 16 '20 at 14:00
  • figured it out and works like a charm! :D thanks for the help! – King Reload Aug 16 '20 at 14:42