WebLogic and Maven in 5 minutes

To set up a Java EE 5 Maven project that works in WebLogic using split-deployment we just need few easy steps.

We start by creating the actual project with a very simple JEE archetype that encloses the minimum necessary to start (from the project open-archetypes):

mvn -DinteractiveMode=false -DarchetypeGroupId=org.openarchetypes

  -DarchetypeArtifactId=multi-javaee5-archetype -DarchetypeVersion=0.0.1-SNAPSHOT

  -DarchetypeRepository=http://open-archetypes.googlecode.com/svn/snapshots-repository/

  -DgroupId=net.lucamasini -DartifactId=wls-jee5

  -Dversion=1.0-SNAPSHOT archetype:generate

With this we have our EAR project with which we could theoretically already start using WebLogic autodeploy (taking the generated ear with the "package" and each time copying it into the domain’s folder "autodeploy"), but it is not the best way to work since from a developer's point of view one of the greatest features of this application is split-deploy/fast-swap.

To enable them we must make some changes only to the pom.xml of the generated project:

Let's see in detail these three steps.

Configuring beabuild-plugin

This activity needs editing three poms, starting from the parent where the plugin-repository is defined as following:

 

<pluginRepositories>

    <pluginRepository>

        <id>beabuild.snapshot</id>

        <name>Beabuild Snapshot Repository</name>

        <url>http://maven-beabuild-plugin.googlecode.com/svn/maven2/snapshots</url>

    </pluginRepository>

    <pluginRepository>

        <id>beabuild.release</id>

        <name>Beabuild Release Repository</name>

        <url>http://maven-beabuild-plugin.googlecode.com/svn/maven2/releases</url>

    </pluginRepository>

and configured within the  plugin-management:

<pluginManagement>

<plugins>

<plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>beabuild-generator-plugin</artifactId>

                <version>0.9.1-SNAPSHOT</version>

                <executions>

                    <execution>

                        <id>generazioneBeabuild</id>

                        <goals>

                            <goal>generate-beabuild</goal>

                        </goals>

                    </execution>

                </executions>

</plugin>

then referenced in the poms of the ear and web modules::

<build>

       <plugins>

          <plugin>

              <groupId>org.apache.maven.plugins</groupId>

              <artifactId>beabuild-generator-plugin</artifactId>

          </plugin>

      </plugins>

</build>

ear-plugin configuration

The ear-plugin already has an initial configuration generated from the archetype, this must be enriched with:

<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>

<filtering>true</filtering>                    

<earSourceExcludes>.beabuild.txt</earSourceExcludes>

<generatedDescriptorLocation>

${project.basedir}/src/main/application/META-INF/

</generatedDescriptorLocation>

Split-deploy with antrun-plugin

In the last step we configure a simple Maven goal such that our application is automatically deployed on WebLogic. To do this we first need to add some properties to point to our WLS installation:

  <properties>

      <weblogic.version>10.3.4</weblogic.version>

      <bea.home>PATH_TO_YOUR_BEA_HOME</bea.home>

      <weblogic.home>${bea.home}\wlserver_10.3</weblogic.home>

  </properties>

and then configure antrun-plugin such that it deploys our project:

<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-antrun-plugin</artifactId>

    <version>1.3</version>

    <configuration>

        <tasks>

            <taskdef name="wldeploy"

                     classname="weblogic.ant.taskdefs.management.WLDeploy"

                     classpathref="maven.plugin.classpath"/>

            <wldeploy action="deploy" verbose="true" debug="true"

                      name="${project.artifactId}" source="${basedir}/src/main/application" user="weblogic"

                      password="*************" adminurl="t3://localhost:7001" targets="AdminServer"/>

        </tasks>

    </configuration>

    <dependencies>

        <dependency>

            <groupId>com.sun</groupId>

            <artifactId>tools</artifactId>

            <version>${java.version}</version>

            <scope>system</scope>

            <systemPath>${java.home}/../lib/tools.jar</systemPath>

        </dependency>

        <dependency>

            <groupId>weblogic</groupId>

            <artifactId>weblogic</artifactId>

            <version>${weblogic.version}</version>

            <scope>system</scope>

            <systemPath>

                ${weblogic.home}/server/lib/weblogic.jar

            </systemPath>

        </dependency>

        <dependency>

            <groupId>weblogic</groupId>

            <artifactId>webservices</artifactId>

            <version>${weblogic.version}</version>

            <scope>system</scope>

            <systemPath>

                ${weblogic.home}/server/lib/weblogic.jar

            </systemPath>

        </dependency>

    </dependencies>

</plugin>

Putting all pieces together

At this point an install is sufficient:

mvn install

and from here on you just need to redo the full deployment for any changes made ​​on the code that fast-swap or the JVM can not exchange on the fly:

mvn ant:run

This command takes care of the first deployment of the application or just updates the modified modules.