Important points to be noted while creating Wildfly modules
1. Custom modules are created in modules folder of Wildfly (Path : {Wildfly-Home}\modules)
2. Wildfly has its own modules which are used by the Wildfly server itself. These modules reside in {Wildfly-Home}\modules\system\base\layer.
Ideally we should not touch these modules but if we want to upgrade or downgrade any Wildfly's module then we can modify that particular module.
3. Most of the core java libraries are there in "javax.api" module and javaee libraries(ie. servlet, jsp, etc) are present in "javaee.api".
These modules are present in system\layer\base folder.
4. Before creating any custom module we should search it in system\layer\base because many of the often used modules are already present their.
Add a custom module we must follow the below steps
a. Download the required jar file from maven repository.
b. Open the archived jar file and check the package name of the jar file.
c. Suppose if we consider jtds-1.3.1.jar and open the jar we can see the package goes till net/sourceforge/jtds
We can give the same name to the module as net.sourceforge.jtd.
d. It is a good practice to use the package name as the module name but we can use any other name for the module.
e. Now create a folder net within modules then sourceforge and then jtds. So the folder structure will be net/sourceforge/jtds.
f. Now create main inside jtds folder . Now it will be net/sourceforge/jtds/main
g. Create module.xml within main folder and also place the downloaded jar file in main.
Structure of folder
Wildfly-Home
--->modules
--->net
--->sourceforge
--->jtds
--->main
--->module.xml
--->jtds-1.3.1.jar
h. Content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="net.sourceforge.jtds">
<resources>
<resource-root path="jtds-1.3.1.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Now the question arise, How dependencies should be identified and added?
We can check the compile time dependencies in the maven repository itself or we will get an exception of the modules dependencies are not fulfilled.
The exception will be like "ClassNotFoundException on module main : net.sourceforge.jtds".
Then we can check in the existing modules in the system\layer\base and add it in dependency.
Include only the required folders
Suppose if we don't want to include the whole system module like "javax.api" then we can just include the required folders like below
<dependencies>
<system export="true">
<paths>
<path name="org/xml/sax"/>
<path name="org/xml/sax/helpers"/>
<path name="javax/xml/parsers"/>
<path name="org/w3c/dom"/>
</paths>
</system>
<module name="org.dom4j"/>
</dependencies>
Exclude some folders from the jar
If we want to exclude some folders to be loaded in the module then we can
<resources>
<resource-root path="core-renderer.jar"/>
<resource-root path="Tidy.jar">
<filter>
<exclude-set>
<path name="org/xml" />
<path name="org/w3c/dom" />
</exclude-set>
</filter>
</resource-root>
</resources>
Comments
Post a Comment