Building OSB projects with Maven and removing the eclipse dependency

In this earlier post, I talked about a way to automate the build and deployment for OSB, but I did not go so far as to get that working in Maven, though you certainly could.  But, OSB PS6 has added a new tool called configjar which lets you build a sbconfig.jar file without needing to have eclipse/OEPE/OSB IDE installed on the machine where you are doing the build.  You do still need OSB, but removing that IDE dependency is a big step forward.

You can find configjar sitting under your Oracle_OSB1/tools/configjar directory in your OSB PS6 installation.  There is a readme file there that tells you how to use it from ANT and WLST.  Here, I want to show you how to use it from Maven, and therefore Hudson, etc. too.

For this post, I went into the OSB IDE and created a simple project called osbProject1 which contains a single Proxy Service called (imaginatively) ProxyService1.  It is just a plain old ‘any’ proxy service with essentially no implementation at all.  But it is enough to do what we need to do.

By the way – I have OSB and the OSB IDE running on Oracle Linux as a 64-bit application – see how here.

The configjar tools supports building sbconfig.jar files for projects and/or resources.  So you should be able to use this same approach for pretty much anything you build in OSB, possibly excepting when you have custom extensions.

If we take a look in my osbProject1 direction in my eclipse workspace, we see that it contains just a single file, ProxyService1.proxy.

We are going to add a few more files:

  • A Maven POM to control the build (pom.xml)
  • A settings.xml file that we will pass to configjar
  • import.py and import.properties files like we had in that previous post

Let’s take a look at them now.  We will start with settings.xml.  This is a file we pass to configjar to tell it how to build the sbconfig.jar for us.  This is a relatively simple file.  Here is an example:

<?xml version="1.0" encoding="UTF-8" ?>
<p:configjarSettings xmlns:p="http://www.bea.com/alsb/tools/configjar/config">
  <p:source>
    <p:project dir="/home/oracle/workspace/osbProject1"/>
    <p:fileset>
      <p:exclude name="*/target/**" />
      <p:exclude name="*/security/**" />
      <p:exclude name="*/.settings/**" />
      <p:exclude name="*/import.*" />
      <p:exclude name="*/alsbdebug.xml" />
      <p:exclude name="*/configfwkdebug.xml" />
      <p:exclude name="*/pom.xml" />
      <p:exclude name="*/settings.xml" />
      <p:exclude name="*/osbProject1.jar" />
    </p:fileset>
  </p:source>
  <p:configjar jar="/home/oracle/workspace/osbProject1/osbProject1.jar">
    <p:projectLevel includeSystem="false">
      <p:project>osbProject1</p:project>
    </p:projectLevel>
  </p:configjar>
</p:configjarSettings>

In the source element, under project we have a dir attribute that points to the OSB project directory that was created by the OSB IDE, and we most likely check out of a version control system before starting our build.  All of those exclude elements are telling it to ignore these extra files we have added to the project, and the ones that it will generate.  Without those, your sbconfig.jar will be polluted with a bunch of unnecessary stuff.  These are all standard from project to project, except for the last one, which is the name of the sbconfig.jar itself.

The jar attribute on the configjar element names the output file.  Finally, we have the project element under projectLevel that names the projects we want to include in the sbconfig.jar that we build.  The other option is to select by resources.  You might want to go check out the OSB documentation to see how to do that.

Next, we have the import.py and import.properties files.  These are essentially the same as in the previous post so I wont repeat them. The only difference is that we need to update import.properties to contain the correct filename:

importJar=osbProject1.jar
1
 

Then we need a POM.  We are going to use the maven-antrun-plugin to execute configjar through ANT to generate the sbconfig.jar, and then the exec-maven-plugin to deploy it to our OSB server.  Here is the POM:

<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.redstack.osb</groupId>
  <artifactId>osbProject1</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies/>
  <properties>
    <osbHome>/ciroot/product_binaries/osb11.1.1.7/Oracle_OSB1</osbHome>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>deafult-cli</id>
            <phase>package</phase>
            <configuration>
              <target>
                <echo>
WARNING
-------
You must set the weblogic.home and osb.home environment variables
when you invoke Maven, e.g.:
mvn compile -Dweblogic.home=/osb11.1.1.7/wlserver_10.3
-Dosb.home=/osb11.1.1.7/Oracle_OSB1
                </echo>
                <taskdef name="configjar"
                  classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask"
                  classpathref="maven.plugin.classpath"/>
                <configjar settingsFile="${basedir}/settings.xml"
                  debug="true">
                </configjar>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-launcher</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-apache-bsf</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>configjar</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/tools/configjar/configjar.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>weblogic.server.modules_10.3.6.0</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../modules/features/weblogic.server.modules_10.3.6.0.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>weblogic</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../wlserver_10.3/server/lib/weblogic.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>oracle.http_client_11.1.1</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.http_client_11.1.1.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>xmlparserv2</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.xdk_11.1.0/xmlparserv2.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>orawsdl</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.webservices_11.1.1/orawsdl.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>wsm-dependencies</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/../oracle_common/modules/oracle.wsm.common_11.1.1/wsm-dependencies.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>osb.server.modules_11.1.1.7</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/modules/features/osb.server.modules_11.1.1.7.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>oracle.soa.common.adapters</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/soa/modules/oracle.soa.common.adapters_11.1.1/oracle.soa.common.adapters.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>log4j_1.2.8</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/lib/external/log4j_1.2.8.jar</systemPath>
          </dependency>
          <dependency>
            <groupId>com.oracle.osb</groupId>
            <artifactId>alsb</artifactId>
            <version>11.1.1.7</version>
            <scope>system</scope>
            <systemPath>${osbHome}/lib/alsb.jar</systemPath>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>deploy</id>
            <phase>pre-integration-test</phase>
            <configuration>
              <executable>/bin/bash</executable>
              <arguments>
                <argument>${osbHome}/../oracle_common/common/bin/wlst.sh</argument>
                <argument>${basedir}/import.py</argument>
                <argument>${basedir}/import.properties</argument>
              </arguments>
            </configuration>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Let’s take a look at the important parts of the POM that you will need to adjust to suit your environment:

  • We define a property called osbHome which is then used throughout the POM.  This needs to point to your Oracle_OSB1 directory.
  • In the plugin section for maven-antrun-plugin you can see that we have a taskdef to import the configjar task from the supplied configjar-ant.xml which comes with OSB.  We also have added a bunch of dependencies to this plugin so that it has the right OSB libraries in the classpath when it executes.  Note that they all have the scope set to system which means you don’t need to import them into a Maven repository first.  You can just specify a path to locate them.  Of course, this ties your build to that one machine effectively.  You can of course just go ahead and put those jars into a Maven repository and then use them normally, though since configjar depends on a local OSB install, there is not a lot of benefit right now.
  • Finally, in the plugin entry for exec-maven-plugin you can see that we execute wlst.sh and pass it our import.py script to do the deployment.

The configjar tool also requires two environment variables to be set, so you need to set these when you run Maven.  Here is an example:

mvn verify -Dweblogic.home=/ciroot/product_binaries/osb11.1.1.7/wlserver_10.3 -Dosb.home=/ciroot/product_binaries/osb11.1.1.7/Oracle_OSB1

This will build the sbconfig.jar and deploy it to OSB for us.  Here it is:

osb

Good luck!  Enjoy!  And a big thank you to Dimitri Laloue who helped me get configjar working.

Add Your Comment