Plugin external libraries

Hi, I have simple plugin that uses external libraries (apache http client) All of them are included in jar file, but they are not loaded by class loader, and it throws NoClassDefFoundError when sponge tries to load the plugin. Idk what am I doing wrong.

stack trace: hastebin

Please show us your build.gradle.

I dont use gradle, I use IntelliJ and its artifacts to build jar, is gradle necessary?

maven works fine too

What you are describing should work anyway, though a build system is a good thing to use. What did you do, specifically? Does your plugin jar contain the Apache classes, or does it contain the Apache jar itself?

It contains extracted classes. That worked for me always, but this is the first time Im working with sponge. I can provide jar here.

Might not be a bad idea.

Forge excludes some packages from loading in mods (prevents inconsistent classloading issues).
You’ll need to shade the package when building. Something like renaming org.apache to gt.creeperface.sponge.shaded.apache or whatever

But then I had to change package name in all apache classes

A shading plugin automatically handles that for you, for gradle you could use something like this: GitHub - johnrengelman/shadow: Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.

I’m sure there are similar tools for maven, or for no build system, that one can find. “java shading” and “fat jar” are good keywords to search for.

1 Like

For maven, use the maven shade plugin.

https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html