Use your Maven build to auto deploy to WebLogic 10.3

Ever wonder how you can deploy to WebLogic server using Maven. In the 10.3 version of WebLogic you can use WLDeploy (an ANT task) to do this in Maven using the antrun plugin. The XML is provided below and what I did is wrap this in a profile called “wlsDeploy”. On our CI build, I simply added -PwlsDeploy to the command line set-up so that it would deploy to WebLogic.

In the code below, you simply need to have the WebLogic JAR available to you on the build server, update the path property variable and replace the other variables with properties in your Maven build or add -D parameters to the run command line, especially for things like passwords.

Once complete, your builds will auto deploy to WebLogic based on your build schedule, assuming you’re using a CI build server for continuous integration. Otherwise, you can run this locally as well.

<plugins>
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <id>local-deploy</id>
                <phase>package</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
                            <classpath>
                                <pathelement path="${path.to.weblogic.jar.local}"/>
                            </classpath>
                        </taskdef>
                        <wldeploy action="stop"
                                  name="${deploy.name}"
                                  failonerror="false"
                                  user="${wls.dev.username}"
                                  password="${wls.dev.password}"
                                  verbose="true"
                                  adminurl="http://${wls.dev.hostname}:${wls.dev.port}"
                                  targets="${wls.deploy.target}"/>
                        <wldeploy action="undeploy"
                                  name="${deploy.name}"
                                  failonerror="false"
                                  user="${wls.dev.username}"
                                  password="${wls.dev.password}"
                                  verbose="true"
                                  usenonexclusivelock="true"
                                  adminurl="http://${wls.dev.hostname}:${wls.dev.port}"
                                  targets="${wls.deploy.target}"/>
                        <wldeploy action="deploy"
                                  name="${deploy.name}"
                                  source="${deploy.source}"
                                  remote="true"
                                  upload="true"
                                  user="${wls.dev.username}"
                                  password="${wls.dev.password}"
                                  verbose="true"
                                  usenonexclusivelock="true"
                                  adminurl="http://${wls.dev.hostname}:${wls.dev.port}"
                                  targets="${wls.deploy.target}"/>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
Advertisements

2 comments on “Use your Maven build to auto deploy to WebLogic 10.3

  1. Hi

    I need your help. I am using maven and wls plugin with usenonexclusivelock set to true. But the weblogic deployment fails complaining about the lock
    “The domain edit lock is owned by another session in non-exclusive mode. This deployment operation requires exclusive access to the edit lock and therefore cannot proceed. If using “Automatically Aquire Lock and Activate Changes” in the Administration Console, then the lock will expire shortly, so retry this operation. InvocationTargetException -> [Help 1]
    [ERROR] ”

    pom.xml snippet:

    <plugin>
    <groupId>com.oracle.weblogic</groupId>
    <artifactId>wls-maven-plugin</artifactId>
    <version>12.1.1.0</version>
    <executions>
    <execution>
    <phase>install</phase>
    <goals>
    <goal>redeploy</goal>
    </goals>
    <configuration>
    <name>content</name>
    <action>redeploy</action>
    <source>filename.war</source>
    <upload>true</upload>
    <remote>true</remote>
    <verbose>true</verbose>
    <middlewareHome>C:\wls1212_dev\wls12120\wlserver</middlewareHome>
    <weblogicHome>C:\wls1212_dev\wls12120\wlserver</weblogicHome>
    <adminurl>t3://localhost:7001/</adminurl>
    <targets>myserver</targets>
    <user>weblogic</user>
    <password>weblogic1</password>
    <stage>false</stage>
    <nostage>true</nostage>
    <usenonexclusivelock>true</usenonexclusivelock>
    </configuration>
    </execution>
    </executions>
    </plugin>

    Any thoughts why the config has got no effect?

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s