Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto update versions in application.xml after maven release

application.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <description>DESCRIPTION</description>
  <display-name>xxxsystem-ear</display-name>
  <module>
    <ejb>xxxsystem-ejb-3.1.1-SNAPSHOT.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>xxxsystem-web-3.1.1-SNAPSHOT.war</web-uri>
      <context-root>/xxxsystem</context-root>
    </web>
  </module>
  <library-directory>lib</library-directory>
</application>

After I run : mvn release:clean mvn release:prepare mvn release:perform

So i have to change the versions of .jar and .war to 3.1.2 in xml file manually.

There is a way to tell maven to change versions in this file for me?

I have to do the same thing with jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </deployment>

    <sub-deployment name="xxx-ejb-3.1.1-SNAPSHOT.jar">
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </sub-deployment>

    <sub-deployment name="xxx-web-3.1.1-SNAPSHOT.war">
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </sub-deployment>
</jboss-deployment-structure>

Any ideas?

like image 916
Claudinei Avatar asked Feb 14 '23 09:02

Claudinei


2 Answers

One good way to do this is to let maven take care of generating the application.xml file:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <filtering>true</filtering>
                <version>6</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <ejbModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>xxxsystem-ejb</artifactId>
                    </ejbModule>
                    <webModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>xxxsystem-web</artifactId>
                        <contextRoot>/xxxsystem</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>

Secondly, the jboss-deployment-structure.xml (assumed to be in src/main/application) can be generated with filtering enabled in the plugin (shown above) and it's source modified as:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </deployment>

    <sub-deployment name="xxxsystem-ejb-${project.version}.jar">
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </sub-deployment>

    <sub-deployment name="xxxsystem-web-${project.version}.war">
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </sub-deployment>
</jboss-deployment-structure>

Alternatively, you can generate the EAR with version-less embedded modules by specifying the module filename:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <version>6</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <ejbModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>xxxsystem-ejb</artifactId>
                        <bundleFileName>xxxsystem-ejb.jar</<bundleFileName>
                    </ejbModule>
                    <webModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>xxxsystem-web</artifactId>
                        <bundleFileName>xxxsystem-web.war</<bundleFileName>
                        <contextRoot>/xxxsystem</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>

in which case filter copying of the jboss-deployment-structure.xml is not required. Each sub-deployment-name would be matched with the bundleFileName used in the maven-ear-plugin configuration.

like image 96
Steve C Avatar answered Feb 17 '23 03:02

Steve C


Why Can You not use simply maven resource plugin? http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

If You configure the files correctly You need to use ${project.version} and its done

like image 39
maslan Avatar answered Feb 17 '23 01:02

maslan