Custom jboss-app.xml using Maven

4.7k views Asked by At

I declared a custom jboss-app.xml in my pom.xml, but the plugin is generating an internal and empty jboss-app.xml file into ear/META-INF.

I created my pom.xml based on this article with the following definition:

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <configuration>
        <data-sources>
            <data-source>${artifactId}/src/main/resources/mytest-ds.xml</data-source>
        </data-sources>
        <jboss>${artifactId}/src/main/resources/jboss-app.xml</jboss>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            </manifest>
        </archive>
        <modules>
            <ejbModule>
                <groupId>com.testproject</groupId>
                <artifactId>ejb-project</artifactId>
            </ejbModule>
        </modules>
    </configuration>
</plugin>

But, I can't handle my custom jboss-app.xml. A new is empty descriptor (without defined ejbs) is generated every time.

3

There are 3 answers

1
Raghuram On

From the docs, it looks like jboss tag triggers the generation of jboss-app.xml. How about omitting this tag and generating the ear?

0
Magna On

You should be able to simply include your jboss-app.xml in your source tree and Maven will pull it in.

Your project directory structure for the maven-ear-plugin should look like:

|-- pom.xml
`-- src
    `-- main
        `-- application
            `-- META-INF
                |-- application.xml
                `-- jboss-app.xml

Then just run mvn package to create your EAR. Assuming the packaging for your pom.xml is 'ear' it will pull jboss-app.xml into your resulting ear.

Also, I believe your <datasources>...</datasources> configuration needs to be within the <jboss>...</jboss> tags.

See also: http://maven.40175.n5.nabble.com/Deployment-of-the-jboss-app-xml-file-td45009.html

0
dma_k On

Alternative would be to pull datasources via application.xml as described here. But as <jarModule> requires are full-blown maven artifact, that is longer way (perhaps for application servers other than JBoss):

project/ds/pom.xml:

<artifactId>project-ds</artifactId>
<packaging>jar</packaging>

<name>My DataSource</name>

project/ds/src/main/resources/my-ds.xml:

<datasources>
    <local-tx-datasource>
    ...

project/ear/pom.xml (assuming that driver is also packaged in EAR):

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>project-ds</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>project-war</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>${jtds.driver.version}</version>
    </dependency>
</dependencies>
...
<plugin>
    <artifactId>maven-ear-plugin</artifactId>

    <configuration>
        <modules>
            <jarModule>
                <groupId>net.sourceforge.jtds</groupId>
                <artifactId>jtds</artifactId>
                <includeInApplicationXml>true</includeInApplicationXml>
            </jarModule>
            <jarModule>
                <groupId>${project.groupId}</groupId>
                <artifactId>project-ds</artifactId>
                <unpack>true</unpack>
                <uri>/</uri>
                <bundleFileName>my-ds.xml</bundleFileName>
                <includeInApplicationXml>true</includeInApplicationXml>
            </jarModule>
            <webModule>
                <groupId>${project.groupId}</groupId>
                <artifactId>project-war</artifactId>
                <contextRoot>${context.path}</contextRoot>
            </webModule>
        </modules>
    </configuration>
</plugin>

Will generate META-INF/application.xml:

<application>
  <display-name>project-ear</display-name>
  <description>...</description>
  <module>
    <java>jtds-1.2.4.jar</java>
  </module>
  <module>
    <java>my-ds.xml</java>
  </module>
  <module>
    <web>
      <web-uri>project-war-1.0.0.war</web-uri>
      <context-root>/</context-root>
    </web>
  </module>
</application>