Search
Calendar
June 2025
S M T W T F S
« May    
1234567
891011121314
15161718192021
22232425262728
2930  
Archives

PostHeaderIcon WebLogic Deployment with Maven: Dynamic Property Settings

Case

You have to deploy a WAR archive on a WebLogic server. To simplify the deployment process, you use weblogic-maven-plugin. Then, you only have to launch a mvn clean install weblogic:deploy to compile and deploy the WAR.

Actually, the plugin configuration expects you to hard write the settings in the pom.xml, such as:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>weblogic-maven-plugin</artifactId>
    <version>2.9.1</version>
    <configuration>
        <name>myWebApplication-web</name>
        <adminServerHostName>localhost</adminServerHostName>
        <adminServerPort>7001</adminServerPort>
        <adminServerProtocol>t3</adminServerProtocol>
        <targetNames>myTargetServer</targetNames>
        <userId>myUserId</userId>
        <password>myPassword</password>
        <securitymodel>Advanced</securitymodel>
        <artifactPath>${project.build.directory}/myWebApplication-web.war</artifactPath>
    </configuration>
</plugin>

Yet, when you work on a multi-environment / multi-developper platform, hard writing the properties bothers. Production teams are not pleased, and, above all, it’s not safe.

Unworking fix

At first glance, I tried to use Maven filtering mechanisms. Anyway, this features was designed for compilation phase: properties are recopied from a property file to the actual one, and then included in the archive generated (may it be JAR, EAR or WAR); in a deployment phase, properties are not taken in account.
http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files

Unelegant fix

Another solution is to set properties by profile. This works, but is not elegant at all: the password for production environment has to reason to be readable in the pom.xml used by a developper!

Fix

WebLogic / Maven plugin

Add the following block:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>weblogic-maven-plugin</artifactId>
  <version>2.9.1</version>
  <configuration>
      <name>myWebApplication-web</name>
      <adminServerHostName>${weblogic.server.name}</adminServerHostName>
      <adminServerPort>${weblogic.server.port}</adminServerPort>
      <adminServerProtocol>${weblogic.server.protocol}
      </adminServerProtocol>
      <targetNames>${weblogic.target}</targetNames>
      <userId>${weblogic.user}</userId>
      <password>${weblogic.password}</password>
      <securitymodel>${weblogic.security}</securitymodel>
      <artifactPath>${project.build.directory}/myWebApplication-web.war
      </artifactPath>
  </configuration>
</plugin>

Properties / Maven plugin

Under the tag, add the block:

<properties>
    <weblogic.server.name>${myTargetServer.server.name}</weblogic.server.name>
    <weblogic.server.port>${myTargetServer.server.port}</weblogic.server.port>
    <weblogic.server.protocol>${myTargetServer.server.protocol}</weblogic.server.protocol>
    <weblogic.user>${myTargetServer.user}</weblogic.user>
    <weblogic.password>${myTargetServer.password}</weblogic.password>
    <weblogic.target>${myTargetServer.target}</weblogic.target>
    <weblogic.security>${myTargetServer.security}</weblogic.security>
</properties>

Within the block, add the the following block:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>conf/${maven.user}.myTargetServer.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

Settings.xml

Optionnaly, in your settings.xml, in your default profile, set the following property:

<profile></pre>
<id>myDefaultProfile</id>
 <properties>
 <maven.user>jonathan_lalou</maven.user>
 </properties>
</profile>

You can decide to bypass this step. In this case, you will have to add the following parameter on launching Maven:
-Dmaven.user=jonathan_lalou

Property file

Create a property file, with a name corresponding to the one you specified in maven.user property.

myTargetServer.server.name=localhost
myTargetServer.server.port=7001
myTargetServer.server.protocol=t3
myTargetServer.user=myUserId
myTargetServer.password=myPassword
myTargetServer.target=myTargetServer
myTargetServer.security=Advanced

Now, you can launch mvn package weblogic:deploy. The WAR will be deployed on the right server.

Leave a Reply