Blog




The smartics-jboss-modules-maven-plugin is a tool to generate JBoss Modules based on the information found in a POM and applies additional information found in modules descriptors. To make reuse of these modules descriptors possible, they are developed in an independent configuration project and attached to the plugin as a dependency.

This short article shows how to do it.

 

For more information about about generating JBoss modules, please refer to smartics-jboss-modules.

The Configuration Project

To create a configuration project just create a Maven project with a packaging type of jar.

<?xml version='1.0'?>
 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.mycorp.config</groupId>
  <artifactId>config-mycorb-jboss-modules</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>
 
  <!-- 
     ... excluded infrastructure (SCM, deployment, ...) configuration here ... 
 
     ... you'll probably also want to fix the version numbers of the 
         used plugins, Maven will tell you that ...
    -->
</project>

These are only a few constraints to follow to add modules descriptors:

  1. The modules descriptor files have to be stored in a folder named jboss-modules within the JAR artifact. Place it in your project at src/main/resources/jboss-modules, so that this folder is automatically included.
  2. The modules descriptor XML files contained in this folder

The project layout looks like this:

You see that we split the modules descriptors semantically in different files. Per convention the name of the file is the name of the module or a semantic name, if there are several modules descriptors in a file. Putting all descriptors in just one file would be ok, too.

Since the src/main/resources folder is automatically included in a JAR, the POM has not to be adjusted. The project’s artifact can be build, installed and deployed as any other project containing resources.

 

For a real-life example, please refer to config-smartics-jboss-modules. This is a configuration we use in our projects and add information that is common to all. So the contents of this project certainly changes in the future.

Modules Descriptors

We already gave an introduction to the modules descriptors in our article Modules Descriptor for smartics-jboss-modules-maven-plugin. Nonetheless here is an example of the contents of the XML file, just to get you the complete picture:

 <?xml version="1.0"?>
<modules xmlns="http://smartics.de/ns/jboss-modules-descriptor/1">
  <module name="com.mysql">
    <match>
      <includes>
        <include>
          <artifactId>mysql-connector-java</artifactId>
        </include>
      </includes>
    </match>
 
    <apply-to-module>
      <dependencies>
        <module name="javax.api" />
      </dependencies>
    </apply-to-module>
  </module>
</modules>

The example shows the descriptor of the MySQL JDBC Driver as a module. It defines the main artifact as a resource and adds a dependency to the standard javax.api provided by JBoss AS. The plugin generates a module.xml from this descriptor.

For details on syntax and semantics, please refer to the article Modules Descriptor for smartics-jboss-modules-maven-plugin already mentioned above.

The Configuration of the Plugin

To add configurations to the plugin add a dependency to the artifact. For instance, to include the modules descriptors of config-smartics-jboss-modules, configure the plugin as follows:

 <plugin>
  <groupId>de.smartics.maven.plugin</groupId>
  <artifactId>smartics-jboss-modules-maven-plugin</artifactId>
  <version>0.2.0</version>
  <executions>
    <execution>
      <id>create-modules-archive</id>
      <goals>
        <goal>create-modules-archive</goal>
      </goals>
      <phase>package</phase>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>de.smartics.config</groupId>
      <artifactId>config-smartics-jboss-modules</artifactId>
      <version>2.0.1</version>
    </dependency>
  </dependencies>
</plugin>

Conclusion

In this short example we have shown that there is absolutely no magic in providing module descriptor files for the smartics JBoss Modules Maven Plugin. Add the configuration artifact to the classpath of your plugin and you are done.

For more articles on this topic, please refer to the project's blog.

 


 

I think the apply-to-dependencies / dependencies / match / excludes is not working with resolved dependencies. At least in version 0.2.0

I believe its because ModuleXmlBuilder line 337 adds the dependency via the addContent method regardless of whether it matched or not from the ApplyToDependencies.getDescriptorThatMatches.
I could of course be completely wrong too.

Thanks,
Eric

Eric Schley. (October 30, 2013 at 7:54 pm)

Hi Eric,

thank you for your comment!

I don’t know, if I understand your problem exactly. I have added a test case that reflects my understanding at http://www.smartics.eu/svn/public/maven/smartics-jboss-modules-maven-plugin/trunk/src/it/apply-dependency-excludes. And the result is correct, I think.

May I ask you to check, if my assumptions are correct?

Maybe you would like to show me the part of your configuration that does not work as expected? Maybe we could discuss this by email (we are currently working to install a mailing list)? We could post the summary of our results here later, for the benefit of others …

Cheers,
Robert

Robert. (October 30, 2013 at 9:20 pm)

I have added an article that may clarify the exclusion topics to our blog: Exclude with smartics-jboss-modules.

Robert. (November 1, 2013 at 12:14 pm)


Link

Link

Posts