The following tutorial will show you how to create the layer.xml file for INTGeoServer plugins. Layer.xml files provide an easy way to register and unregister capabilities in INTGeoServer. It is similar in concept to the Java "ServiceLoader" API, but with the added benefits of a hierarchy and position attributes.
For example, when INTGeoServer starts, every context listener registered in the layer.xml file is executed. As layer.xml files are carried along with .jar files, this allows an easy way to plug capabilities, by just adding that .jar file to the WEB-INF/lib folder. No manual modification to the web.xml file is needed, reducing opportunities for deployment errors.
The following tutorial was performed with the NetBeans IDE. A similar set of actions could be performed with the Eclipse IDE as INTGeoServer doesn't depend on the IDE used.
First, we need to create the services folder in the META-INF directory. The casing of META-INF must be respected.
Right-click your project's Source Packages folder, and select New->Other.
From the following menu, select Other, and then select Folder, and then click Next >.
Enter META-INF as the Folder Name, and then click Finish.
We need to do the same procedure one more time. This time, instead of right-clicking Source Packages, right-click the newly created META-INF folder, and choose New->Other. Select Other, and then select Folder, and click Next >.
For the Folder Name use services, and then click Finish. The casing of services must be respected.
Right-click the META-INF.services directory, and select New->Other. In this next panel select Other, select Empty File. Click Next >.
For the File Name use layer.xml. Click Finish. The casing of layer.xml must be respected.
The following code is the basic skeleton structure for layer.xml files:
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
</filesystem>
This layer.xml file is "empty" from a functional point of view: no class is registered. The DOCTYPE line references the NetBeans DTD, but NetBeans is not required to edit this file.
When INTGeoServer starts, all library files in the WEB-INF/librarypath/amd64 are added automatically to the java.library.path. If the architecture detected is Intel x86 , the WEB-INF/librarypath/x86 directory will be used instead.
This feature is implemented as a AbstractIntGeoServerInitializer that is registered in the layer.xml file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="com.interactive.intgeoapi.server.lifecycle.AbstractIntGeoServerInitializer">
<file name="com.interactive.intgeo.server.lifecycle.LibraryPathInitializer.instance">
<attr name="position" intvalue="10"/>
</file>
</folder>
</filesystem>
Let's inspect the content of this layer.xml file:
The folder name com.interactive.intgeoapi.server.lifecycle.AbstractIntGeoServerInitializer indicates the fully qualified name of the interface or abstract class being implemented.
The file name com.interactive.intgeo.server.lifecycle.LibraryPathInitializer.instance indicates the fully qualified name of the implementation to register. The .instance suffix indicates that this is a positive registration, as opposed to the .instance_hidden suffix that will be discussed in the next section.
The position 10 indicates that this context listener should be executed after all others that have a lower position number have been executed. The position attributes do not need to be sequential; there can be position gaps between two position values.
If you want to plug your own implementation of the context listener that sets the java.library.path, you would typically "negate" the built-in entry and register your own.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="com.interactive.intgeoapi.server.lifecycle.AbstractIntGeoServerInitializer">
<file name="com.interactive.intgeo.server.lifecycle.LibraryPathInitializer.instance_hidden">
<file name="com.mycompany.intgeo.server.lifecycle.MyInitLibraryPathContextListener.instance">
<attr name="position" intvalue="10"/>
</file>
</folder>
</filesystem>
The .instance_hidden suffix effectively unregisters the associated class.
The JBOSS application server might warn about the presence of layer.xml files in the META-INF/services folders:
2016-12-19 22:53:46,434 WARN [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015893: Encountered invalid class name '<?xml version="1.0" encoding="UTF-8"?>' for service type 'layer.xml'
These warnings should be ignored.
INTGeoServer v3 uses registration annotations