Gelunox
Gelunox

Reputation: 792

Java plugin library shading

I'm building a Java based HTTP Server with a bukkit-like (minecraft) plugin system. And I want to load plugin libraries in such a way that they don't interfere with each other, e.g. if two plugins package the same library in their jar something might go wrong.

I know this can be done with "maven shading". However, the only thing about maven I know is how to add dependencies to a project. And maven tutorials are not making me any wiser.

I have read up about somethings like build goals, yet nowhere any pom.xml examples explaining how this works or what kind of options you have. And when I search for "Java plugin maven shading" or similar the only results I get are about the maven shading plugin (which I don't understand the first thing about either)

I don't want to get too deep into maven commandline, I'm using a eclipse maven plugin.

Other solutions are welcome as well.

Upvotes: 1

Views: 262

Answers (1)

Gelunox
Gelunox

Reputation: 792

Someone on another forum told me to search in the context of fat jar which helped me find my answer. I found this website with a nice example of how to package the jar file:

<!-- Maven Shade Plugin -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.3</version>
  <executions>
    <!-- Run shade goal on package phase -->
    <execution>
        <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <transformers>
          <!-- add Main-Class to manifest file -->
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>com.mkyong.core.utils.App</mainClass>
          </transformer>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>

Upvotes: 1

Related Questions