Follow Us on Twitter

Building OSB 12c releases on resource level using Maven

by Mike Heeren on January 12, 2017 · 15 comments

A while ago I published a Whitebook (in Dutch) about building OSB 12c releases on resource level using Maven. In the Whitebook, you could read which functionality we were missing in the regular Oracle Service Bus plugin for Maven and how we were able to create this functionality using a custom Maven plugin.

I have added the code of this custom Maven plugin to the following public repository: https://bitbucket.org/whitehorsesbv/servicebusplugin

Used settings

The custom Maven plugin has been developed and tested on multiple environments, so we can confirm that the Maven plugin is working if you are using the following version(s):

Application Version
Java 1.7.0_79, 1.8.0_101
Maven 3.3.9
Oracle Service Bus 12.1.3, 12.2.1

Installing the custom Maven plugin

First start to install the custom Maven plugin to your local Maven repository. To do this, you can download both the JAR and the POM file from the download page of the repository. After you have downloaded both files, you can execute the following commands to install it to you local Maven repository:

mvn install:install-file -Dfile=servicebus-plugin-1.0.jar -DgroupId=nl.whitehorses.servicebus -DartifactId=servicebus-plugin -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=servicebus-plugin-1.0.pom -DgroupId=nl.whitehorses.servicebus -DartifactId=servicebus-plugin -Dversion=1.0 -Dpackaging=pom

Building a Service Bus project on resource level

Now that the custom Maven plugin is available in the Maven repository, we are able to build OSB projects using this plugin instead of the default Oracle plugin. To do so, open the pom.xml file in the OSB project directory. By default, the pom.xml file will look something like the below example:

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<parent> 
		<groupId>com.oracle.servicebus</groupId> 
		<artifactId>sbar-project-common</artifactId> 
		<version>12.1.3-0-0</version> 
	</parent> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Employee</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<packaging>sbar</packaging> 
	<description/> 
</project>

If we package the project into an archive using the above pom.xml file by executing mvn package via the command line, we will get an archive that can be used to deploy the OSB project on project level to the OSB. The build archive can be found in the .data/maven folder within the project directory.

If we change the value of the pom.xml file to the below example, and we package the project the project using the same command, we will get an archive  which can be used to deploy on resource level via the OSB. In the below example the following files will be added to the archive:

  • All files within the Business directory.
  • All files within the Pipeline directory, except UpdateEmployee.pipeline.

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Employee</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<packaging>sbar</packaging> 
	<build> 
		<directory>${project.basedir}/.data/maven</directory> 
		<sourceDirectory>${project.basedir}</sourceDirectory> 
		<resources> 
			<resource> 
				<directory>${project.basedir}</directory> 
			</resource> 
		</resources> 
		<plugins> 
			<plugin> 
				<groupId>nl.whitehorses.servicebus</groupId> 
				<artifactId>servicebus-plugin</artifactId> 
				<version>1.0</version> 
				<extensions>true</extensions> 
				<configuration> 
					<!-- Configure the Oracle Home directory --> 
					<oracleHome>C:\Oracle\Middleware1221\Oracle_Home</oracleHome> 
					<!-- Specify whether this is a system release --> 
					<system>false</system> 
					<!-- Configure the export level of the release, possible values are PROJECT and RESOURCE --> 
					<exportLevel>RESOURCE</exportLevel> 
					<!-- Optional parameter to specify which of the resources should be included into the archive --> 
					<includes> 
						<include>**/Business/*</include> 
						<include>**/Pipeline/*</include> 
					</includes> 
					<!-- Optional parameter to specify which of the resources should be excluded from the archive --> 
					<excludes> 
						<exclude>**/Pipeline/UpdateEmployee.pipeline</exclude> 
					</excludes> 
				</configuration> 
			</plugin> 
		</plugins> 
	</build> 
</project>

Instead of using the includes and excludes tags, we can also add a resources tag to the pom.xml file, which points towards a configuration file. This can be used to specify which files need to be included and excluded. For example, the below files will result in exactly the same archive as we would get using the includes and excludes tags: 

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Employee</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<packaging>sbar</packaging> 
	<build> 
		<directory>${project.basedir}/.data/maven</directory> 
		<sourceDirectory>${project.basedir}</sourceDirectory> 
		<resources> 
			<resource> 
				<directory>${project.basedir}</directory> 
			</resource> 
		</resources> 
		<plugins> 
			<plugin> 
				<groupId>nl.whitehorses.servicebus</groupId> 
				<artifactId>servicebus-plugin</artifactId> 
				<version>1.0</version> 
				<extensions>true</extensions> 
				<configuration> 
					<!-- Configure the Oracle Home directory --> 
					<oracleHome>C:\Oracle\Middleware1221\Oracle_Home</oracleHome> 
					<!-- Specify whether this is a system release --> 
					<system>false</system> 
					<!-- Configure the export level of the release, possible values are PROJECT and RESOURCE --> 
					<exportLevel>RESOURCE</exportLevel> 
					<!-- Optional parameter to specify which of the resources should be included into and excluded from the archive --> 
					<resources>C:\JDeveloper\mywork\Whitehorses\Employee\archiveResources.xml</resources> 
				</configuration> 
			</plugin> 
		</plugins> 
	</build> 
</project>

archiveResources.xml

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
	<!-- Optional parameter to specify which of the resources should be included into the archive --> 
	<includes> 
		<include>**/Business/*</include> 
		<include>**/Pipeline/*</include> 
	</includes> 
	<!-- Optional parameter to specify which of the resources should be excluded from the archive --> 
	<excludes> 
		<exclude>**/Pipeline/UpdateEmployee.pipeline</exclude> 
	</excludes> 
</resources>

Adding an Assembly project to add multiple projects to single archive

The final step of creating full OSB release archives on resource level, was that we wanted to add multiple projects to a single archive. We achieved this by first building every OSB project separately, and later build an Assembly application which combines all projects into a single archive file. To do this, we use the parent pom.xml file to build all projects (including the assembly project). It is important that the assembly project is build last.

The parent pom.xml file, which will build every project, including the assembly project, will look something like the below example:

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Whitehorses</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<packaging>pom</packaging> 
	<modules> 
		<!-- All OSB projects --> 
		<module>Clockwise</module> 
		<module>Employee</module> 
		<module>Office</module> 
		<!-- Assembly project --> 
		<module>Assembly</module> 
	</modules> 
</project>

The pom.xml file of the Assembly project will look like the below example. It is important that if you add new projects, you don’t only add them to the parent pom.xml file, but you also add them as a dependency to the Assembly project. 

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Assembly</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<dependencies> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Clockwise</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Employee</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Office</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
	</dependencies> 
	<build> 
		<finalName>sbconfig_${project.version}</finalName> 
		<plugins> 
			<plugin> 
				<artifactId>maven-jar-plugin</artifactId> 
				<version>2.6</version> 
				<executions> 
					<execution> 
						<id>default-jar</id> 
						<phase>never</phase> 
					</execution> 
				</executions> 
			</plugin> 
			<plugin> 
				<artifactId>maven-assembly-plugin</artifactId> 
				<version>2.6</version> 
				<configuration> 
					<appendAssemblyId>false</appendAssemblyId> 
					<descriptors> 
						<descriptor>${basedir}/src/main/assembly/assembly.xml</descriptor> 
					</descriptors> 
				</configuration> 
				<dependencies> 
					<dependency> 
						<groupId>nl.whitehorses.servicebus</groupId> 
						<artifactId>servicebus-plugin</artifactId> 
						<version>1.0</version> 
					</dependency> 
				</dependencies> 
				<executions> 
					<execution> 
						<id>make-assembly</id> 
						<phase>package</phase> 
						<goals> 
							<goal>single</goal> 
						</goals> 
					</execution> 
				</executions> 
			</plugin> 
		</plugins> 
	</build> 
</project>

This pom.xml file also points to an assembly.xml file, which contains some configuration about how the Assembly archive should be build bij the Maven assembly plugin. This assembly.xml file should look like the below example: 

assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> 
	<id>src</id> 
	<formats> 
		<format>sbar</format> 
	</formats> 
	<includeBaseDirectory>false</includeBaseDirectory> 
	<dependencySets> 
		<dependencySet> 
			<outputDirectory>/</outputDirectory> 
			<unpack>true</unpack> 
		</dependencySet> 
	</dependencySets> 
</assembly>

If you navigate to the directory which contains the parent pom.xml file, and you execute mvn install via the command line, the OSB release will be build.

For a working example of the above, please download: Building-OSB-12c-releases-on-resource-level-using-Maven.zip

Deploying the archive via Maven

It is also possible to deploy the generated (Assembly) archive directly to an OSB server via the Maven plugin. To achieve this, we should add the deploy-assembly goal of the custom Maven plugin to the desired Maven phase. We chose the pre-integration-test phase for deploying the archive to the OSB server. The pom.xml file in the Assembly project can be updated like the below example to connect the Maven pre-integration-test phase to the deploy-assembly goal of the Maven plugin:

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	<modelVersion>4.0.0</modelVersion> 
	<groupId>nl.whitehorses</groupId> 
	<artifactId>Assembly</artifactId> 
	<version>1.0-SNAPSHOT</version> 
	<dependencies> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Clockwise</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Employee</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
		<dependency> 
			<groupId>nl.whitehorses</groupId> 
			<artifactId>Office</artifactId> 
			<version>1.0-SNAPSHOT</version> 
			<type>sbar</type> 
		</dependency> 
	</dependencies> 
	<build> 
		<finalName>sbconfig_${project.version}</finalName> 
		<plugins> 
			<plugin> 
				<artifactId>maven-jar-plugin</artifactId> 
				<version>2.6</version> 
				<executions> 
					<execution> 
						<id>default-jar</id> 
						<phase>never</phase> 
					</execution> 
				</executions> 
			</plugin> 
			<plugin> 
				<artifactId>maven-assembly-plugin</artifactId> 
				<version>2.6</version> 
				<configuration> 
					<appendAssemblyId>false</appendAssemblyId> 
					<descriptors> 
						<descriptor>${basedir}/src/main/assembly/assembly.xml</descriptor> 
					</descriptors> 
				</configuration> 
				<dependencies> 
					<dependency> 
						<groupId>nl.whitehorses.servicebus</groupId> 
						<artifactId>servicebus-plugin</artifactId> 
						<version>1.0</version> 
					</dependency> 
				</dependencies> 
				<executions> 
					<execution> 
						<id>make-assembly</id> 
						<phase>package</phase> 
						<goals> 
							<goal>single</goal> 
						</goals> 
					</execution> 
				</executions> 
			</plugin>
			<plugin>
				<groupId>nl.whitehorses.servicebus</groupId> 
				<artifactId>servicebus-plugin</artifactId> 
				<version>1.0</version> 
				<executions>
					<execution>
						<id>deploy-assembly</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>deploy-assembly</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins> 
	</build> 
</project>

If we navigate to the directory containing the parent pom.xml file again, we will be able to deploy the release to the OSB server by executing the mvn pre-integration-test statement. The following parameters must/can be added to this command:

Parameter Required? Default value
-Dserver.url Yes
-Dserver.username Yes
-Dserver.password Yes
-Ddeployment.preserve.credentials true
-Ddeployment.preserve.envValues true
-Ddeployment.preserve.operationalValues true
-Ddeployment.preserve.securityAndPolicyConfig true
-Ddeployment.preserve.accessControlPolicies true
-Ddeployment.customization.file No
-Ddeployment.session.activate true
-Ddeployment.session.discardOnError true

 

These settings represent the “Advanced Settings” when manually uploading an archive via the servicebus console.

Good luck building your OSB releases on resouce level using Maven!

Building OSB 12c releases on resource level using Maven, 5.0 out of 5 based on 1 rating
Ratings:
VN:D [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)

{ 15 comments… read them below or add one }

Alfonso January 14, 2017 at 1:12 am

Hi Mike,
Great post !!!

One question, to deploy the project in the OSB. I guess one should execute the “mvn pre-integration-test” command via the command line at the parent pom.xml file. Right?

Reply

Mike Heeren January 16, 2017 at 9:53 am

Hi Alfonso,

With a few steps you will be able to deploy the project to the OSB server using the pre-integration-test phase indeed. I have added these steps to the article!

Reply

Alfonso January 16, 2017 at 8:23 pm

Hi Mike,
Thanks for your reply and update to the article.

After following your instructions to do the deployment, I am having the following error:

[ERROR] Failed to execute goal nl.whitehorses.servicebus:servicebus-plugin:1.0:deploy-assembly (deploy-assembly) on project Assembly: Unable to import artifact [/Whitehorses/Assembly/target/sbconfig_1.0-SNAPSHOT.sbar] to session [ServiceBusPlugin_Assembly_1484590426986]: error: Use of undefined namespace prefix: imp -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal nl.whitehorses.servicebus:servicebus-plugin:1.0:deploy-assembly (deploy-assembly) on project Assembly: Unable to import artifact [/Whitehorses/Assembly/target/sbconfig_1.0-SNAPSHOT.sbar] to session [ServiceBusPlugin_Assembly_1484590426986]

I am having this same issue trying to deploy your project and also my project (which also is configured to use the custom plugin)

Appreciate your help

Reply

Alfonso January 16, 2017 at 8:48 pm

Hi Mike,

When deploying your project and my project.

I am getting the following error:

[ERROR] Failed to execute goal nl.whitehorses.servicebus:servicebus-plugin:1.0:deploy-assembly (deploy-assembly) on project Assembly: Unable to import artifact [/Whitehorses/Assembly/target/sbconfig_1.0-SNAPSHOT.sbar] to session [ServiceBusPlugin_Assembly_1484590426986]: error: Use of undefined namespace prefix: imp -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal nl.whitehorses.servicebus:servicebus-plugin:1.0:deploy-assembly (deploy-assembly) on project Assembly: Unable to import artifact [/Whitehorses/Assembly/target/sbconfig_1.0-SNAPSHOT.sbar] to session [ServiceBusPlugin_Assembly_1484590426986]

More details:
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to import artifact [/Users/alfonso/Downloads/Whitehorses/Assembly/target/sbconfig_1.0-SNAPSHOT.sbar] to session [ServiceBusPlugin_Assembly_1484590426986]
…..
Caused by: org.apache.xmlbeans.XmlException: error: Use of undefined namespace prefix: imp
……
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Searching through the project I did not find any “imp” prefix.

Have you come across this error?

Reply

Alfonso January 16, 2017 at 9:26 pm

HI Mike,

The only reference to the “imp” qualifier was by opening the “ExportInfo” file (inside an sbarfile). In there, I saw the following namespace: xmlns:imp=”http://www.bea.com/wli/config/importexport”

The content is basically an XML and everything seems ok. The qualifier is being used in the elements.

Any ideas?

Reply

Alfonso January 17, 2017 at 5:14 am

Hi Mike,

Based on my last reply, I confirm you that the issue I was having was the namespace prefix at the ExportInfo file inside the .sbar file which contains more than one project (which is located in the folder Assembly/target)

I did some changes in the Java class “nl.whitehorses.servicebus.archiver.SbarArchiver.java” of the plugin.
Basically the changes was to allow the appearance of the prefix in the corresponding elements.

Then I re-built the plugin (mvn package), re-install it as mentioned in your article (mvn install:install-file -Dfile=servicebus-plugin-1.0.jar -DgroupId=nl.whitehorses.servicebus -DartifactId=servicebus-plugin -Dversion=1.0 -Dpackaging=jar)

Finally, I redeployed the OSB projects (in a bundle): mvn pre-integration-test

NOTE: please let me know if by any chance you had this same issue during deployment. Also I will be more than welcome to share with you the changes on the Java class, just let me know. It would be great to know your point of view regarding the changes I did.

Reply

Mike Heeren January 17, 2017 at 8:39 am

Hi Alfonso,

Which version of OSB are you using? I have just checked for OSB 12.1.3 and I don’t see the issue there. Perhaps there is a difference in the expected content of the ExportInfo file between OSB 12.1.3 and OSB 12.2.1.

Reply

Alfonso January 17, 2017 at 3:28 pm

I am using version 12.2.1

Reply

Mike Heeren January 17, 2017 at 8:45 pm

Hi Alfonso,

I found a difference in the generated ExportInfo file between OSB 12.1.3 and 12.2.1 indeed. I have fixed the issue and uploaded a new version (1.1) of the JAR and POM file to the download page. If you download and install this version to you local Maven repository, and use this version in your pom.xml files, you should be able to build and deploy your archives.

Please let me know if you have any issues!

Reply

Alfonso January 17, 2017 at 10:51 pm

Hi Mike,

I managed to test the 1.1 version without any troubles.

Just for the sake of this article, to install/run version 1.1 it is needed to:
1)- Install the jar and pom file executing:

mvn install:install-file -Dfile=servicebus-plugin-1.1.jar -DgroupId=nl.whitehorses.servicebus -DartifactId=servicebus-plugin -Dversion=1.1 -Dpackaging=jar

mvn install:install-file -Dfile=servicebus-plugin-1.1.pom -DgroupId=nl.whitehorses.servicebus -DartifactId=servicebus-plugin -Dversion=1.1 -Dpackaging=pom

2)- Update the value of the element in following POM files:
– At the project level
– Inside the Assembly project/folder

The changes would be in this section (specifically in the value of the element):

nl.whitehorses.servicebus
servicebus-plugin
1.1 ———> HERE
….

Regards

Reply

Alfonso January 25, 2017 at 9:08 pm

Hi Mike,

Is there a way to change the location of the .sbar file that gets generated?

As you know, this file is located in a folder which name is “target”. Is it possible to specify a different name for that folder. A way to specify this could be, for example, in the pom.xml file (inside the Assembly folder).

Thanks

Reply

Mike Heeren January 26, 2017 at 8:54 am

Hi Alfonso,

Yes, this can be achieved via the Assembly pom.xml file. Just add a directory element within the build element. For example:


<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.whitehorses</groupId>
<artifactId>Assembly</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
...
</dependencies>
<build>
<directory>${project.basedir}/custom_target_dir</directory>
<finalName>sbconfig_${project.version}</finalName>
<plugins>
...
</plugins>
</build>
</project>

Reply

Alfonso February 1, 2017 at 8:26 pm

Hi Mike,

Thanks for your reply.

For the plugin to work, is it mandatory to have configured maven.oracle.com as a repository in settings.xml (in .m2 folder)?

Reply

Mike Heeren February 8, 2017 at 6:30 pm

Hi Alfonso,

Yes, you will need to be able to access the Oracle Maven repository. You can read more about how to connect to the Oracle Maven repository here: http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm

Reply

erpsandeep February 11, 2017 at 2:03 pm

It’s a Nice Blog to read and share thanks for posting. Post as many blogs it can be more important………….

Reply

Leave a Comment

 

Previous post:

About Whitehorses
Company profile
Services
Technology

Whitehorses website

Home page
Whitebooks
Jobs

Follow us
Blog post RSS
Comment RSS
Twitter