Maven is a commonly used build system for java projects. It provide benefits ranging from standardizing project layouts, to automated dependency fetching, to automated builds and Maven.
Oracle provides a pretty comprehensive document outlining how to build and create Oracle SOA and BPM projects using Maven. See this article that documents some simple steps to get up and running using Maven. However, when running my first Maven project I encountered some unexpected errors. Maven could not find any SOA archetypes and was also unable to load every dependency. As I found, being able to create, build, and deploy SOA and BPM projects using Maven requires some initial pre-work. Once the set-up is done, the Oracle doc mentioned above will make more sense and will execute successfully.
Why Maven in SOA Applications?
Unlike Ant, Maven does not require developers to specify every command to achieve a goal. Moreover, Maven’s structure in the form of a POM file allows dependencies to be managed easily. However, the biggest benefit is that Maven in JDeveloper provides complete a life-cycle process. Each goal incorporates the previous one and adds functionality. For example, if we run the mvn test command, it will execute the compile, package and deploy commands before running each test on the composite. The idea is to provide a foundation for continuous development and integration. A single command can compile, package, deploy and run all test cases: saving you time.
Gradle provides much of the same functionality of Maven but on a different format. It is implemented using Groovy and, as a result, some of its scripts are much shorter than Maven’s. Unfortunately, Gradle is not native to JDeveloper at this moment.
Documentation lists five goals for the SOA Maven Plug-in. However, The plug-in itself lists six goals.
compile: Compiles the Application
package: Creates a SAR file of the composite
deploy: Deploys the SOA composite
test: Runs all test created for the SOA composite
undeploy: Removes the composite
help: Provides a list of goals and their corresponding commands.
The help goal is the only goal not listed in the actual Oracle document but displayed on the plug-in itself. While the “help” command may not be a “Goal”, It provides useful information regarding goals, commands, and what each command tries to achieve.
Set Up Your Local Maven
Maven 3.0.5 files are included in your Middleware installation. You can access them in the following location
I find installing Maven easier by using Maven’s home page instructions and files. Just follow Maven in 5 minutes and you will be up and running Maven commands in a short time. Remember where your m2 repository is installed and make sure you can run basic Maven commands such as build and help. I am using Maven’s 3.2.3 version, howver, Maven has newer version available.
Install Oracle Maven Plug-in and Configure Local Repository
In order to support CI environments, we can use Maven without a local Weblogic installation but we will need to install the Oracle Maven plug-in. The plug-in is located in your Weblogic home location. It should be inside the following location:
The location should have two files. The executable for the plug in as well as a POM file.
Open a command window navigate to the folder where the plug-in is located and run the following:
mvn install:install-file -DpomFile=oracle-maven-sync-12.1.3.pom -Dfile=oracle-maven-sync-12.1.3.jar
Run the ‘Push’ Command to upload all the Oracle Maven artifacts to your local repository. The push command goes out and imports all the necessary libraries for SOA, BPM and ADF libraries needed to run projects in the m2 Maven repository. It populates your local repository with all the Maven artifacts. The default m2 location is at oracleHome/m2/repository. I prefer to specify the path of the repository to make sure all artifacts are imported in the location i want. To do that, run the following command:
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/path/to/your/oracleHome -Dmaven.repo.local=/path/to/your/m2/repository
It should look as the following:
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/Oracle/MiddlewareJDev12.1.3 -Dmaven.repo.local=/Users/AC0034/.m2/repository
Run mvn crawl command in your m2 repository in order to update the archetype catalog
mvn archetype:crawl -Dcatalog=/path/to/your/m2/archetype-catalog.xml. It should look as the following: mvn archetype:crawl -Dcatalog=/Users/AC0034/.m2/archetype-catalog.xml
It is not necessary to run the ‘crawl’ command. However, there is a chance the repository is not updated with the Oracle archetypes and plug ins. ‘Crawl’ ensures the repository picks up the newly added files. At this point, the Oracle Maven Plug in and your local repository should now be all set and you can finally create a SOA or BPM application using Maven.
Creating Your App Using Maven Archetype
Archetypes are ways to provide structure or a template to create applications. There are two ways to create a project using an archetype: the command line or, once a local repository is set, from Jdeveloper directly.
Oracle 12c Maven plug-in comes with two basic archetypes for SOA applications: Application and Archetype. If you try it using the command window, simply run the following command to generate the application and done.
The Oracle document mentioned at the beginning of this article explains in detail what each one of the options means and how to tweak them. Alternatively, if you are not much of a fan of creating an application from the command window, you can create your application using the JDeveloper user interface because your local m2 repository contains the Oracle archetypes. To create the app from JDeveloper do the following:
Create new Maven application:
Enter your app information, click on select Maven archetype:
Type SOA in the search box and you should see Oracle’s archetypes available in your local repository. You should see two (SOA-Application and SOA-Project). If your local repository is not set up properly, the local repository option will be grayed out and unavailable:
Select the one, click ok and finish:
You can navigate to the resources folder to see the auto-generated POM created from the archetype. The POM generated from the archetype looks a little different than a POM created from a basic SOA Application. You will notice tags such as model version, package and parameters for each one of the Maven goals. It does not mean that as a developer you cannot add such tags and have your project compile and execute using Maven. Archetypes provided by Oracle are templates designed to provide guidance as to how and where files and instructions should be placed.
Oracle 12c includes more support for Maven out of the box than before. One of the first things you notice when creating a new SOA application in 12c is the “resources” directory with the POM file in it. However, building a SOA application using Maven is not as straight forward and, as with many of 12c’s functionality, you need to do some prework configuration before diving in and taking advantage of all the capabilities. However, once the set-up is done, following Oracle’s documentation for creating and building SOA application using Maven is pretty straight forward and easy to follow.