SagaciousZed (talk | contribs) m (→Append the classpath: typo) |
m (Reverted edits by 172.68.35.94 (talk) to last revision by Sagacious Zed) |
||
(12 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | There are several |
+ | In order to use external libraries in Bukkit plugins, the server must have the required libraries on the classpath. There are several method available that plugins can use to get their libraries onto the classpath. |
==Shade the external libraries into the plugin’s jar== |
==Shade the external libraries into the plugin’s jar== |
||
Line 5: | Line 5: | ||
==Declaring a class-path attribute in the manifest== |
==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/ |
+ | 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 the maven-jar-plugin, but is not required to be made. Additional information about the maven-jar-plugin can be found at http://maven.apache.org/plugins/maven-jar-plugin/ |
− | For example, class-path <code>./lib/example.jar</code> declares that example.jar is in the lib |
+ | For example, class-path <code>./lib/example.jar</code> 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== |
==Instruct the classloader to load more jars== |
||
Line 14: | Line 14: | ||
==Append the classpath== |
==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 |
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 |
||
+ | |||
+ | [[Category:Tutorials]] |
Latest revision as of 17:04, 21 July 2016
In order to use external libraries in Bukkit plugins, the server must have the required libraries on the classpath. There are several method available that plugins can use to get their libraries onto the classpath.
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/
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 the maven-jar-plugin, but is not required to be made. 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