BukkitWiki

Welcome to the BukkitWiki!

This Wiki is home to Bukkit's documentation and regulations surrounding the Bukkit Project and it's services. Want to help out? We would love to have you! Signup to get started!

READ MORE

BukkitWiki
mNo edit summary
Quantum7 (talk | contribs)
Line 3: Line 3:
 
==Shade the external libraries into the plugin’s jar==
 
==Shade the external libraries into the plugin’s jar==
 
A plugin can copy the dependencies into the jar, this can be done with maven-shade-plugin. Plugins should relocate their dependencies to avoid conflicts between plugins, which may result in <s>nausea, vomiting, upset stomach, and/or death</s> unintended behavior or exceptions. Additional information about the maven-shade-plugin can be found at http://maven.apache.org/plugins/maven-shade-plugin/
 
A plugin can copy the dependencies into the jar, this can be done with maven-shade-plugin. Plugins should relocate their dependencies to avoid conflicts between plugins, which may result in <s>nausea, vomiting, upset stomach, and/or death</s> unintended behavior or exceptions. Additional information about the maven-shade-plugin can be found at http://maven.apache.org/plugins/maven-shade-plugin/
  +
  +
To enable shade with your plugin, add the following code to your <tt>pom.xml</tt>:
  +
  +
<pre>
  +
<project>
  +
<build>
  +
<plugins>
  +
<plugin>
  +
<groupId>org.apache.maven.plugins</groupId>
  +
<artifactId>maven-shade-plugin</artifactId>
  +
<version>1.3.1</version>
  +
<executions>
  +
<execution>
  +
<phase>package</phase>
  +
<goals>
  +
<goal>shade</goal>
  +
</goals>
  +
<configuration>
  +
<minimizeJar>true</minimizeJar>
  +
</configuration>
  +
</execution>
  +
</executions>
  +
</plugin>
  +
</plugins>
  +
</build>
  +
</project>
  +
</pre>
  +
  +
The jar can then be built by running
  +
<tt>mvn package</tt>
  +
from your project root. By default the jar will be in <tt>target/[project name]-[version].jar</tt>
   
 
==Declaring a class-path attribute in the manifest==
 
==Declaring a class-path attribute in the manifest==

Revision as of 22:56, 5 September 2013

There are several options available to plugins that wish to leverage additional libraries during runtime.

Shade the external libraries into the plugin’s jar

A plugin can copy the dependencies into the jar, this can be done with maven-shade-plugin. Plugins should relocate their dependencies to avoid conflicts between plugins, which may result in nausea, vomiting, upset stomach, and/or death unintended behavior or exceptions. Additional information about the maven-shade-plugin can be found at http://maven.apache.org/plugins/maven-shade-plugin/

To enable shade with your plugin, add the following code to your pom.xml:

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.3.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <minimizeJar>true</minimizeJar>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The jar can then be built by running mvn package from your project root. By default the jar will be in target/[project name]-[version].jar

Declaring a class-path attribute in the manifest

A plugin can declare a class-path attribute in the jar’s manifest. The classpath is relative to the jar itself, and not where the jvm was invoked from. Plugins should not make any assumptions as to the location of the plugins folder, and cannot be placed in the root of the plugin folder. The entry can be made with maven-jar-plugin. Additional information about the maven-jar-plugin can be found at http://maven.apache.org/plugins/maven-jar-plugin/

For example, class-path ./lib/example.jar declares that example.jar is in the lib directory in the plugins folder. The plugins folder itself however, can be defined as a command line argument to CraftBukkit.

Instruct the classloader to load more jars

A plugin can have their classloader load additional jars.

Append the classpath

Additional jars can be added to the classpath for the jvm with the -cp flag or changing the CLASSPATH environment variable. This is something the plugin itself should not do and must be completed at the discretion of the server administrator. Additional information can be found at http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html