Technical

Installing WebLogic with Maven

In a previous post we created a WLST script that created a WebLogic domain from scratch, turned the servers on and deploy a jar file. It almost provided everything we needed from a continuous integration perspective, except that we needed WebLogic installed before we could run the WLST script. This meant that we couldn’t spin up a blank VM and start this script. The immediate solution to that would probably be to script the installation of WebLogic (you can create a silent install file so that WebLogic installs without any user intervention required). A better solution would be to use Maven. Maven is a project build tool that we can use to compile our java projects and run various plugins to install WebLogic, start servers and deploy code. For more information on Maven check out the Maven presentation from the July Oracle Middleware Forum.

(The example Maven file from this post is available at Github: https://github.com/Joelith/Maven-Install-WLS)

Before we can create a maven script to build our domain we need to install Maven. Maven is included in the 12c releases of WebLogic so for this example we will use that. Of course this means that we have to install WebLogic before having access to Maven which doesn’t meet our goal of starting from a blank VM. Having said that, Maven is relatively easy to install and you can either install it from a script, a package manager or have it in your base VM image without having to install WebLogic.

So we’ve installed Maven, now we need to set up our repository. This repository will store our dependencies and importantly we will add the WebLogic zip file to this repository so that we can access when we need to install WebLogic from scratch. Again, since this is an example we will just use the local repository that comes from the Maven installed in WebLogic, in a real life situation you would use a central repository or something like Artifactory/Archiva if you want a nice GUI. You don’t need to do anything to use the local repository in WebLogic, it will be created the first time you run Maven. Make sure you add Maven to the PATH environment variable (in my case this was /oracle/product/wls12130/oracle_common/modules/org.apache.maven_3.0.5)

With the repository started we now need to add the WebLogic artifacts into it. This is because Oracle doesn’t provide a public repository for these artifacts and we will rely on them later in our script. If they aren’t there Maven will not know where to download them from. To do this run the following commands (these are for 12.1.3 of WebLogic, adjust to reflect the version you are using)

cd /oracle/product/wls12130/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.3
mvn install:install-file -DpomFile=oracle-maven-sync-12.1.3.pom -Dfile=oracle-maven-sync-12.1.3.jar
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/oracle/product/wls12130/

Next we need to install the weblogic plugin and the zip file. We are going to install the WebLogic zip into the repository so that we can use it from any machine. This means we don’t need to provide the large zip file for our installation, just the code and the maven pom file.

cd ${MW_HOME}/wlserver/server/lib
mvn install:install-file -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml
mvn install:install-file -Dfile=wls1213_dev.zip -DgroupId=com.oracle.weblogic -DartifactId=wls-dev -Dpackaging=zip -Dversion=12.1.3.0

Notice the -Dversion flag, this means that we can add the new weblogic version (when it comes out) without overriding any script that relies on the 12.1.3 version. Dependency management at work!

With that done, we can now deploy our app and install WebLogic. Let’s generate an example app using the archetype feature of Maven. This provides standard templates for a variety of different java projects. You can either grab the github project or we can create it from scratch by using the archetype feature of Maven.

mvn archetype:generate -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp -DarchetypeVersion=12.1.3-0-0 -DgroupId=com.oracle.canberra -DartifactId=my-webapp -Dversion=1.0-SNAPSHOT

This will generate an app along with a pom.xml file. In that pom file, replace the executions with the following:

<executions>
          <!-- Install WebLogic --> 
          <execution>
            <id>install-wls</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>install</goal>
            </goals>
            <configuration>
              <installDir>${project.build.directory}/software</installDir>
              <artifactLocation>com.oracle.weblogic:wls-dev:zip:12.1.3.0</artifactLocation>
            </configuration>
          </execution>
          <!-- Create Domain -->
          <execution>
            <id>wls-create-domain</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>create-domain</goal>
            </goals>
            <configuration>
              <middlewareHome>${project.build.directory}/software/wls12130</middlewareHome>
              <domainHome>${project.build.directory}/base_domain</domainHome>
              <user>weblogic</user>
              <password>welcome1</password>
            </configuration>
          </execution>
          <!-- Start the Admin Server -->
          <execution>
            <id>wls-start-server</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start-server</goal>
            </goals>
            <configuration>
              <domainHome>${project.build.directory}/base_domain</domainHome>
            </configuration>
          </execution>
          <!--Deploy the application to the server-->
          <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase> 
            <goals> 
              <goal>deploy</goal> 
            </goals>
            <configuration> 
              <user>weblogic</user> 
              <password>welcome1</password>
              <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
              <verbose>true</verbose> 
              <name>${project.build.finalName}</name>
            </configuration> 
          </execution>
          <!-- Post Integration Phase -->
          <!-- Stop Server -->
          <execution>
            <id>wls-stop-server</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop-server</goal>
            </goals>
            <configuration>
              <domainHome>${project.build.directory}/base_domain</domainHome>
              <user>weblogic</user>
              <password>welcome1</password>
              <adminUrl>t3://localhost:7001</adminUrl>
            </configuration>
          </execution> 
          <execution>
            <id>wls-remove-domain</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>remove-domain</goal>
            </goals>
            <configuration>
              <domainHome>${project.build.directory}/base_domain</domainHome>
            </configuration>
          </execution>
          <execution>
            <id>wls-uninstall</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>uninstall</goal>
            </goals>
            <configuration>
              <middlewareHome>${project.build.directory}/software/wls12130</middlewareHome>
            </configuration>
          </execution>
        </executions>

Basically each of the execution sections defines a piece of work we want done and the phase element defines at which Maven lifecycle point this will occur. Executions are done in order if they are for the same phase. So this script will:

  • Install WebLogic: Note that artifactLocation element defines the path to the zip file we installed in Maven before
  • Create a domain: It is set to install in the build directory
  • Start the admin server
  • Stop the admin server: Note this and the following steps only run in the post-integration phase. So WebLogic will have been installed and started and any other tests run before we get here
  • Remove the domain
  • Uninstall WebLogic

We can run this script with `mvn deploy` to have it build, test and tear down the environment or `mvn pre-integration-test` to just install WebLogic and start the server (you can test it by going to localhost:7001/console)

With this we can now start adding more tests and really customising how our code is built. Keep in mind that JDeveloper 12c also uses Maven so these scripts will work with it as well.

Advertisements

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