Weblogic deployment using the Oracle weblogic maven plugin

0

With the PS3 release of the SOA Suite a new version, 10.3.4, of Weblogic has been released. Amongst others, this release also includes a new Weblogic Maven plugin (weblogic-maven-plugin) that allows interaction with Weblogic from within a Maven environment. As far as I know, this plugin is the successor of the Codehaus Weblogic plugin. That one was a bit difficult to use because it required some other not publicly available Weblogic dependencies which have now been included with the new plugin. Unfortunately, this plugin is not (yet?!) available in any of the public Maven repositories so you have to put it in your own repository. Because of the size (more than 50 MB) the plugin is not included with Weblogic as-is but must be created first just as other weblogic client utilities. The documentation of the new plugin describes in detail how to create and use the plugin. In this blog I’ll summarize them (NB, I assume you’re a little bit familiar Maven).

In summary:

  1. Create the plugin.
  2. Deploy it to an artifact repository.
  3. Use the plugin in your project.

Create the plugin

The Weblogic JarBuilder is a utility to create a variety of client jars, now including the maven plugin.

Go to MW_HOME/wlserver_10.3/server/lib/ and issue the command:

<em>java -jar wljarbuilder.jar -profile weblogic-maven-plugin</em>.

This creates the plugin file weblogic-maven-plugin.jar.

Deploy the generated jar file to your Maven artifact repository.

You can install it in your local repository only, but it’s better to deploy it to your company repository and make it easily available for others to use too. Use the pom.xml file that’s included in the generated jar file (META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml) because it includes the identification of the plugin and its dependencies. Extract the pom file and issue the following command:

mvn deploy:deploy-file -Dfile=weblogic-maven-plugin.jar
                       -DpomFile=pom.xml
                       -DrepositoryId=amisrepo-third-party
                       -Durl=http://reposerver/nexus/content/repositories/thirdparty/

(NB use your own url and repositoryId) or use the webinterface of the repository (e.g. Nexus) as you can see in this picture.

upload-maven-weblogic-plugin

Use the plugin in a project.

For this you need a maven enabled project. Since JDeveloper provides very limited support for Maven I assume that most ADF projects are not Maven enabled and that ant and / or the standard JDeveloper deploy deploy profile is used to build the war and ear file. This example expects the ear file to be present in the application’s deploy directory. Add the following pom.xml file to the application’s root directory (NB Use where your own identification and file name):

&lt;?xml	version="1.0"	encoding="UTF-8" ?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;nl.amis.demo.xyz&lt;/groupId&gt;
  &lt;artifactId&gt;mysimpleapp&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;mysimpleapp example application&lt;/name&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;com.oracle.weblogic&lt;/groupId&gt;
        &lt;artifactId&gt;weblogic-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;10.3.4&lt;/version&gt;
        &lt;configuration&gt;
          &lt;adminurl&gt;t3://localhost:7101&lt;/adminurl&gt;
          &lt;user&gt;weblogic&lt;/user&gt;
          &lt;password&gt;weblogic1&lt;/password&gt;
          &lt;upload&gt;true&lt;/upload&gt;
          &lt;action&gt;deploy&lt;/action&gt;
          &lt;remote&gt;false&lt;/remote&gt;
          &lt;verbose&gt;true&lt;/verbose&gt;
          &lt;source&gt;deploy/mysimpleapp.ear&lt;/source&gt;
          &lt;name&gt;mysimpleapp&lt;/name&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;

You can now use Maven from the command line to deploy the earfile to weblogic:

mvn com.oracle.weblogic:weblogic-maven-plugin:deploy

Other commands that are available are: undeploy, redeploy, start-app, stop-app, list-app, update-app and help. These commands are similar to those supported by the command-line utility, weblogic.Deployer, which is actually not surprising because the Maven plugin is actually a wrapper around this weblogic.Deployer. Each command allows different parameters, as described in the weblogic-Maven-plugin documentation (by the way, the documentation also describes how to shorten the usage to mvn weblogic:deploy). Unfortunately, the plugin passes all arguments as-is to weblogic.Deployer and when an argument is not allowed, it raises an error and the process results in a build failure. This occurs for example with the source argument and the commands undeploy, start-app and stop-app. This means that you cannot use one configuration for all the commands (e.g. deploy and undeploy) and must use a workaround. Probably the easiest one is to provide the source argument as a command-line parameter like -Dsource=deploy/mysimpleapp.ear. Another option could be to use multiple profiles with different configurations for deploy and undeploy. I hope this will be fixed soon.

By the way, deployment to an earlier Weblogic, e.g. 10.3.3.0, works too and also to the JDeveloper embedded Weblogic.

Use the plugin in a Maven enabled project

Now, when your application is maven enabled I would recommend a slightly different approach and to use a separate deployment project that is solely aimed at deploying the application. Use the maven dependency plugin to retrieve the ear file from your company repository and define profiles for different servers. This provides better control of the deployment and allows different versions to be deployed to different servers. An ideal situation for a build server like Hudson. This is an example:

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;parent&gt;
    &lt;groupId&gt;nl.amis.demo.xyz&lt;/groupId&gt;
    &lt;artifactId&gt;mysimpleapp&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  &lt;artifactId&gt;mysimpleapp-deploy&lt;/artifactId&gt;
  &lt;name&gt;mysimpleapp deployment&lt;/name&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;properties&gt;
    &lt;app.deploy.version&gt;${project.version}&lt;/app.deploy.version&gt;
    &lt;ear.filename&gt;${project.build.directory}\mysimpleapp-ear-${app.deploy.version}.ear&lt;/ear.filename&gt;
  &lt;/properties&gt;
  &lt;profiles&gt;
    &lt;profile&gt;
      &lt;id&gt;local&lt;/id&gt;
      &lt;activation&gt;
        &lt;activeByDefault&gt;false&lt;/activeByDefault&gt;
      &lt;/activation&gt;
      &lt;properties&gt;
        &lt;wls.admin.url&gt;t3://localhost:7101&lt;/wls.admin.url&gt;
        &lt;wls.admin.username&gt;weblogic&lt;/wls.admin.username&gt;
        &lt;wls.admin.password&gt;weblogic1&lt;/wls.admin.password&gt;
      &lt;/properties&gt;
    &lt;/profile&gt;
  &lt;/profiles&gt;
  &lt;build&gt;
     &lt;plugins&gt;
       &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.5&lt;/version&gt;
        &lt;configuration&gt;
          &lt;skip&gt;true&lt;/skip&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
         &lt;groupId&gt;com.oracle.weblogic&lt;/groupId&gt;
         &lt;artifactId&gt;weblogic-maven-plugin&lt;/artifactId&gt;
         &lt;version&gt;10.3.4&lt;/version&gt;
         &lt;configuration&gt;
           &lt;adminurl&gt;${wls.admin.url}&lt;/adminurl&gt;
          &lt;user&gt;${wls.admin.username}&lt;/user&gt;
           &lt;password&gt;${wls.admin.password}&lt;/password&gt;
           &lt;upload&gt;true&lt;/upload&gt;
           &lt;action&gt;deploy&lt;/action&gt;
           &lt;remote&gt;false&lt;/remote&gt;
           &lt;verbose&gt;true&lt;/verbose&gt;
           &lt;source&gt;${ear.filename}&lt;/source&gt;
           &lt;name&gt;mysimpleapp&lt;/name&gt;
         &lt;/configuration&gt;
       &lt;/plugin&gt;
       &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.1&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;copy-ear&lt;/id&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;copy&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
              &lt;artifactItems&gt;
                &lt;artifactItem&gt;
                  &lt;groupId&gt;nl.amis.demo.xyz&lt;/groupId&gt;
                  &lt;artifactId&gt;mysimpleapp-ear&lt;/artifactId&gt;
                  &lt;version&gt;${app.deploy.version}&lt;/version&gt;
                  &lt;type&gt;ear&lt;/type&gt;
                  &lt;overWrite&gt;true&lt;/overWrite&gt;
                  &lt;outputDirectory&gt;target&lt;/outputDirectory&gt;
                &lt;/artifactItem&gt;
              &lt;/artifactItems&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
   &lt;/build&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;nl.amis.demo.xyz&lt;/groupId&gt;
      &lt;artifactId&gt;mysimpleapp-ear&lt;/artifactId&gt;
      &lt;version&gt;${app.deploy.version}&lt;/version&gt;
      &lt;type&gt;ear&lt;/type&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/project&gt;

You can now perform a deployment with the following statement:

mvn package com.oracle.weblogic:weblogic-maven-plugin:deploy -Plocal

The package goal is to retrieve the ear file from the repository and the -Plocal activates the local profile and thus the arguments for the local weblogic. I have the maven-deploy-plugin configured to prevent this artifact to be deployed to the artifact repository (Note that for Maven the term deploy means deploying to the artifact repository, not the application server (I know, it’s a bit confusing)).

The argument app.deploy.version allows to override the version (that defaults to the project version), for example:

mvn clean package com.oracle.weblogic:weblogic-maven-plugin:deploy -Plocal -Dapp.deploy.version=1.5

The documentation also describes how to bind the plugin to a maven lifecycle phase, e.g. the install phase. This will deploy the ear file when the install phase is executed. This is actually a good idea, but since the install phase is executed quite often (mvn clean install is a normal way to execute the maven build lifecycle) it’s also good practice to use profiles to prevent continuous deployment. An often used practice is to bind deployment to the pre-integration-test phase and undeployment to the post-integration-test phase, but only when you actually perform an integration test. I’m not including examples for that, if you’re interested let me know.

To summarize. The weblogic-maven-plugin is a very valuable plugin for deployment to Weblogic by Maven, it performs great and I will certainly use it on my projects. I’m especially happy with deployment to earlier versions of Weblogic too.

Share.

About Author

Aino Andriessen is a consultant on Enterprise Java, ADF, PL/SQL, XML, and SOA development and is Expertise Lead on Application Lifecycle Management (ALM). He has a strong interest in ADF, SOA, Maven, architecture, quality management, delivery and application lifecycle management. Aino publishes on the AMIS technology blog and has been a presenter at the ODTUG Kaleidoscope, Oracle Open World and UKOUG TechEbs.

Leave a Reply