Rants, Thoughts and Code

How to: Deploy to Weblogic Using Maven

I have always liked Maven due to its simplicity and being so powerful. One of the recent requirement needed deploying to a remote Weblogic server. Since I was using maven for dependency management and all other purposes maven is well known for, I decided to use it for remote deployment as well. Following are the steps one need to follow to make this tick.

Step 1: Getting prerequisites ready

1. A working maven installation. If you don’t have, get that here
2. Weblogic server installation with a valid domain. Get that here

Step 2: Generate Weblogic maven plugin
1
2
3
cd to Oracle Middleware installation directory
For eg: cd MW_HOME/wlserver_XX.X/server/lib/
java -jar wljarbuilder.jar -profile weblogic-maven-plugin
Step 3: Get the pom file to the weblogic lib directory
1
jar xvf MW_HOME/wlserver_XX.X/server/lib/weblogic-maven-plugin.jar META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml

and then

1
cp MW_HOME/wlserver_XX.X/server/lib/META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml MW_HOME/wlserver_XX.X/server/lib
Step 4: Configure the shortened command line goal

Add plugin groups to maven settings.xml (one can find this in conf directory of maven installation. It is apache-maven-3.0.4/conf/ for me) similar to below.

1
2
3
<pluginGroups>
    <pluginGroup>com.oracle.weblogic</pluginGroup>
</pluginGroups>

then edit the pom.xml in MW_HOME/wlserver_XX.X/server/lib/ similar to the below one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.oracle.weblogic</groupId>
  <artifactId>weblogic-maven-plugin</artifactId>
  <packaging>maven-plugin</packaging>
  <version>12.1.1.0</version>
  <name>Maven Mojo Archetype</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.0.4</version>
    </dependency>
 </dependencies>
</project>

execute the mvn install from MW_HOME/wlserver_XX.X/server/lib/ directory

1
mvn install

configure the Weblogic maven plugin to be used in local maven installation

1
mvn install:install-file -Dfile=MW_HOME/wlserver_XX.X/server/lib/weblogic-maven-plugin.jar -DpomFile=pom.xml

Now the plugin is ready to use.

Step 5: Add build goal to your pom.xml

To configure the build goal edit your project pom.xml like the below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<build>
  <plugins>
      <plugin>
          <groupId>com.oracle.weblogic</groupId>
          <artifactId>weblogic-maven-plugin</artifactId>
          <version>12.1.1.0</version>
          <configuration>
              <!-- Provide the ip address of the remote server if remote deployment-->
              <adminurl>t3://localhost:7001</adminurl>
              <user>weblogic_admin_user_id</user>
              <password>admin_password</password>
              <upload>true</upload>
              <action>deploy</action>
              <!-- Change to true if remote deployment-->
              <remote>false</remote>
              <verbose>true</verbose>
              <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
              <name>${project.build.finalName}</name>
          </configuration>
          <executions>
              <execution>
                  <phase>install</phase>
                  <goals>
                      <goal>deploy</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
  </plugins>
</build>

Bingo! You are done.
Start your Weblogic server and one can invoke following goal from project directory.

1
mvn clean install