Jump to content

Recommended Posts

Posted (edited)

 I shaded apache-dbcp2 into my .jar, but when server reaches any usage of this library's classes - it throws NoClassDefFoundError:

[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoClassDefFoundError: org/apache/commons/dbcp2/BasicDataSource
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at ru.alastar.minedonate.rtnl.ModDataBase.getDataBaseConnection(ModDataBase.java:38)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at ru.alastar.minedonate.rtnl.ModDataBase.initDataBase(ModDataBase.java:132)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	... 43 more
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp2.BasicDataSource
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.net.URLClassLoader.findClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.lang.ClassLoader.loadClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.lang.ClassLoader.loadClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:106)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.lang.ClassLoader.loadClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.lang.ClassLoader.loadClass(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [java.lang.Throwable:printStackTrace:-1]: 	... 45 more
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: java.lang.NullPointerException
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at ru.alastar.minedonate.rtnl.ModDataBase.getDataBaseConnection(ModDataBase.java:26)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at ru.alastar.minedonate.rtnl.ModDataBase.getNewStatement(ModDataBase.java:65)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at ru.alastar.minedonate.MineDonate.loadServerMerch(MineDonate.java:95)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at ru.alastar.minedonate.proxies.ServerProxy.preInit(ServerProxy.java:65)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at ru.alastar.minedonate.MineDonate.preInit(MineDonate.java:654)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at java.lang.reflect.Method.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:627)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at java.lang.reflect.Method.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:218)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:196)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at java.lang.reflect.Method.invoke(Unknown Source)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.LoadController.redirect$onPost$zza000(LoadController.java:560)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:627)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:98)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:332)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:125)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:486)
[20:02:37] [Server thread/INFO] [STDERR]: [ru.alastar.minedonate.MineDonate:loadServerMerch:118]: 	at java.lang.Thread.run(Unknown Source)

 On the 1.7.10 everything worked fine

Edited by Alastar
Posted (edited)

Posting my build.gradle that did the trick(Used ShadowJar due to inability to did it with Forge Gradle) seems like the only way to do it now :
 

buildscript {
    
    repositories {
        jcenter()
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
    }
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'java' // or 'groovy'. Must be explicitly applied
apply plugin: 'com.github.johnrengelman.shadow'

version = "0.7.1.26"
group = "minedonate"
archivesBaseName = "minedonate"

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceCompatibility = targetCompatibility = '1.8'
compileJava {
    sourceCompatibility = targetCompatibility = '1.8'
}

minecraft {
    version = "1.12.2-14.23.0.2491"
    runDir = "run"
    mappings = "snapshot_20170612"
    makeObfSourceJar = false
}

configurations {
    shadow
    compile.extendsFrom shadow
}

dependencies {
    shadow   'org.apache.commons:commons-dbcp2:2.1.1'
    shadow   'org.apache.commons:commons-pool2:2.4.2'
    shadow   'mysql:mysql-connector-java:8.0.11'
}
shadowJar {
    archiveName = tasks.jar.archiveName
    configurations = [project.configurations.shadow]
    relocate 'org.apache.commons', 'ru.alastar.org.shadowedlibs.org.apache.commons'
}

jar {
    configurations.shadow.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}
jar.dependsOn shadowJar
jar.enabled = false

processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
        expand 'version': project.version, 'mcversion': project.minecraft.version
    }

    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

 

Edited by Alastar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.