I need to generate module.xml
file for JBoss7 for a maven project which has a lot of jar-dependencies. What is the easiest way to do it? The file looks like:
<module xmlns="urn:jboss:module:1.0" name="ats.platform">
<resources>
<resource-root path="dom4j-1.6.1.jar"/>
<resource-root path="jdom-1.0.jar"/>
...
</resources>
</module>
so that the <resource-root>
element should be created for each project jar-dependency.
Or maybe I doing something wrong? What's correct way to create a JBoss7 module from a maven project?
I don't really know about JBoss and whether there's another way to do this, but you can do it quite simply with GMaven:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<configuration>
<source>
def sw = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(sw)
xml.module(xmlns:'urn:jboss:module:1.0', name:'ats.platform') {
resources {
project.runtimeClasspathElements.each {
def path = it.find(".*?([\\w\\.-]*\\.jar)") { it[1] }
!path?:'resource-root'(path:path)
}
}
}
println sw
</source>
</configuration>
</plugin>
A couple of things to note:
runtimeClasspathElements
contain absolute paths to the jar, which is why I parse it with a regex. You can adjust the regex to include more of the path or just prepend a string if you need more than just the jar file name.I've posted a working example on github (it's just a POM) where I've bound the above plugin configuration to the initialize build phase. If you have git, you can clone and run it yourself with:
git clone git://github.com/zzantozz/testbed tmp
cd tmp
mvn -q initialize -pl stackoverflow/7755255-gmaven-to-build-xml-from-classpath
In the sample project, I added jdom 1.0 and dom4j 1.6.1 as dependencies, and here's the output it created:
<module xmlns='urn:jboss:module:1.0' name='ats.platform'>
<resources>
<resource-root path='jdom-1.0.jar' />
<resource-root path='dom4j-1.6.1.jar' />
<resource-root path='xml-apis-1.0.b2.jar' />
<resource-root path='aspectjrt-1.6.11.jar' />
</resources>
</module>
Note: I'm not a groovy expert, so there may be a groovier way to do it, but you can see how easy it is even so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With