Here is a simple example of how you might organize your project using ant (http://ant.apache.org) as the build tool. This is just a recommendation that we have found to be working well. You may choose to do it another way.
Create a directory on your computer where you want
to store your plug-in project. This directory is the
directory in the listing below. You should also create some subdirectories:
pluginname
/
pluginname
/
pluginname
/bin/
pluginname
/lib/
pluginname
/src/org/company
/
pluginname
/META-INF/
The
bin/
directory is empty to start with. It will contain the compiled code.
In the lib/
directory you should put BASE2Core.jar
and other library files your plug-in depends on. The
src/
directory contains your source code. In this directory you should create
subdirectories corresponding to the package name of your plug-in
class(es). See http://en.wikipedia.org/wiki/Java_package for information
about conventions for naming packages. The
META-INF
directory contains metadata
about the plug-in and are needed for best functionality.
In the root of your directory, create the build file:
build.xml
.
Here is an example that will compile your plug-in and put it in a JAR file.
Example 26.1. A simple build file
<?xml version="1.0" encoding="UTF-8"?> <project name="MyPlugin" default="build.plugin" basedir="." > <!-- variables used --> <property name="plugin.name" value="MyPlugin" /> <property name="src" value="src" /> <property name="bin" value="bin" /> <!-- set up classpath for compiling --> <path id="classpath"> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> </path> <!-- main target --> <target name="build.plugin" description="Compiles the plug-in and put in jar" > <javac encoding="ISO-8859-1" srcdir="${src}" destdir="${bin}" classpathref="classpath"> </javac> <jar jarfile="${plugin.name}.jar" basedir="bin" manifest="META-INF/MANIFEST.MF" > <!--Include this to add required files for auto registration wizard--> <metainf file="META-INF/base-plugins.xml"></metainf> <metainf file="META-INF/base-configurations.xml"></metainf> </jar> </target> </project>
If your plug-in depends on other JAR files than the
BASE2Core.jar
you must create a file called
MANIFEST.MF
in the project META-INF
directory. List the other JAR files as in the following example.
If your plug-in does not depend on other JAR files, you may remove the
manifest
attribute of the <jar>
tag.
Manifest-Version: 1.0 Class-Path: OtherJar.jar ASecondJar.jar
See also Section 26.8, “How BASE load plug-in classes” for more information regarding class loading when a plug-in depends on a external JAR files.
If your plug-in should support registration with the auto-installation
wizard it is a good idea to add the metainf
tags. This will add the two files META-INF/base-plugins.xml
and META-INF/base-configurations.xml
to the
META-INF
directory in the JAR file. The two files
contains information about your plug-in and BASE can automatically
find and extract information from those. See
Section 26.1.3, “Make the plug-in compatible with the auto-installation wizard”
for get more information about this feature.
Compile the plug-in simply by typing
ant
in the console window. If all went well the
MyPlugin.jar
will be created in the same directory.
To install the plug-in copy the JAR file to the server including the dependent JAR files (if any). Place all files together in the same directory. For more information read Section 22.1, “Installing plug-ins”.
If somebody is willing to add information to this chapter please send us a note or some written text to put here. Otherwise, this chapter will be removed.
BASE has support for automatically detecting new plug-ins with the auto-installation wizard. The wizard makes it very easy for a server administrator to install new plug-ins. See Section 22.1.3, “Automatic installation of plug-ins”.
The auto-install feature requires that a plug-in provides some information
about itself. The wizard looks in all JAR file for the file
META-INF/base-plugins.xml
. This file contains
some information about the plug-in(s). Here is an example:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plugins SYSTEM "base-plugins.dtd" > <plugins jarname="jarfile.jar"> <pluginclass classname="se.lu.thep.PluginClass"> <minbaseversion>2.4</minbaseversion> <hasconfigurations/> </pluginclass> . . . </plugins>
The first two lines should be the same in all base-plugins.xml
files.
The rest of the tags are described in following list.
<plugins>
This is the root element in the XML-file and must have the
attribute
jarname
set. The value must be the same as name of the JAR file
the plug-in is located in or the auto-installation wizard
will fail with an error.
<pluginclass>
This tag defines information about a plug-in in the JAR file. The
classname
attribute needs to have the full classname of the plug-in's main
class. There can be one or several of this element inside the
<plugins>
tag, which means that there should be one element for
each plug-in in the JAR file.
<minbaseversion>
A required child element in
<pluginclass>
.
This defines from which version of BASE the plug-in can be used.
The plug-in will not be included in auto installer if the
BASE-version is lower then the value of this tag. The format of the
value in this tag should be (numeric)
majorversion.minorversion.
It is not possible to check the bugfix or revision numbers.
<hasconfigurations>
A required child element in
<pluginclass>
.
This should tell if there are plug-in configurations
shipped with the plug-in. Setting the value to
yes
will indicate that there are available configurations in the
JAR file. This can be left as an empty tag if no
configurations are available for import.
Configurations shipped with a JAR file should be exported with the
plug-in configuration exporter in BASE. The exported file must be
given the name
base-configurations.xml
and be placed in
META-INF/
.