AVIO Consulting

Building SOA 12c Projects that Include Java Code with Maven

Aug 20, 2015 | BPM, Java, Maven

While testing the Maven build scripts I shared in my previous post, I found a few issues while building more complex composite projects.  Both of the issues I found were related to included Java code in the project. One of which has a work around while the other does not.

The first issue was with using the Java Embedding activity in a BPEL process.  This results in a Java class being generated for the BPEL process, which then was failing to compile.

The second issue was with custom Java classes in the SOA composite project which were then used in a Spring component.  These classes were not being compiled, causing an exception at run time when the spring bean was invoked.

BPEL and Java Embedding

Inside that activity I put a simple System.out.prinln as shown:

Now, when I try to build the project using the default Maven POM file with no changes I receive the following error:

[INFO] [exec] /home/adesjard/jdeveloper/mywork/SOAApplication/SOAProject1/SOA/SCA-INF/bpel/
error: package com.collaxa.cube.engine.ext.bpel.v1.nodes does not exist
[INFO] [exec] /home/adesjard/jdeveloper/mywork/SOAApplication/SOAProject1/SOA/SCA-INF/bpel/
error: package com.oracle.bpel.client does not exist
[INFO] compile: [cmd:[/opt/oracle/java/jdk1.7.0_76/jre/bin/java,
|oracle.fabric.common.uddiurl.handler, oracle.soa.scac.ValidateComposite,
/home/adesjard/jdeveloper/mywork/SOAApplication/SOAProject1/SOA//composite.xml, -level=1]] exit code=1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.445s
[INFO] Finished at: Tue Aug 18 16:15:45 CDT 2015
[INFO] Final Memory: 17M/303M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.oracle.soa.plugin:oracle-soa-plugin:12.1.3-0-0:compile
(default-compile) on project SOAProject1: SOA COMPILE FAILED with value: 1 -> [Help 1]

As you can see above the compile fails to compile. It looks like the required libraries containing the com.collaxa.cube.engine.ext.bpel.v1.nodes and com.oracle.bpel.client packages are not available on the classpath of the SCA compiler.

Unfortunately, this has been reported as Bug 20229616 with Oracle previously and has not been resolved yet.

For now you should avoid using the Java Embedding activity in your SOA 12c projects if you want to be able to build the projects with Maven.

Spring Components

The second issue arose when I tried to use a Spring component as an alternative to the Java Embedding activity.

I created a simple Java class called LoggerBean as an example in my SOA composite project as shown below:

After setting up a Spring context exposing this bean as a SCA service, I added Assign and Invoke activities:

We can now see that the project builds fine:

[INFO] --- oracle-soa-plugin:12.1.3-0-0:sar (default-sar) @ SOAProject1 ---
[INFO] Building sar: /home/adesjard/jdeveloper/mywork/SOAApplication/SOAProject1/target/sca_SOAProject1_rev4.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.927s
[INFO] Finished at: Tue Aug 18 16:25:58 CDT 2015
[INFO] Final Memory: 16M/438M
[INFO] ------------------------------------------------------------------------
Process exited with exit code 0.

But when we try and deploy the composite to the server we will get the following error:

Deploying on partition "default" of "/Domain_bpm_domain/bpm_domain/soa_cluster" ...
Deploying on "/Domain_bpm_domain/bpm_domain/soa_cluster" failed!
There was an error deploying the composite on soa_server1: Deployment Failed:
Error occurred during deployment of component:
Spring1 to service engine: implementation.spring for composite: SOAProject1:
SCA Engine deployment failure.: org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [com.avioconsulting.LoggerBean] for bean with name 'loggerBean' defined in URL
nested exception is oracle.classloader.util.AnnotatedClassNotFoundException:

Missing class: com.avioconsulting.LoggerBean

Dependent class: org.springframework.util.ClassUtils
Loader: sun.misc.Launcher$AppClassLoader@828263870
Code-Source: /opt/oracle/product/oracle_home/oracle_common/modules/org.springframework_3.1.0.jar
Configuration: /opt/oracle/product/oracle_home/oracle_common/modules/org.springframework_3.1.0.jar

This load was initiated at default.composite.SOAProject1.soa_99a99cb4-a00b-47ae-bec5-36d0ca856cf0:4.0-SNAPSHOT
using the loadClass() method.

Fortunately, this issue does have a workaround.  While trying to resolve this issue I found that although the sourceDirectory is being set to SOA/SCA-INF/src and the outputDirectory is set to SOA/SCA-INF/classes in the POM file, the Java compile goal is never executed.  This is because the packaging for the POM is defined as sar which causes the oracle-soa-plugin:12.1.3-0-0:compile goal to be executed instead.

In order to work around this issue, you can add the following plugin definition to your POM which will run the Java compile goal after the SOA compile goal has completed.  


You should then see output like below during your build and have your compiled Java classes inside of your SAR file.

[INFO] --- maven-compiler-plugin:3.3:compile (compile-soa-java) @ SOAProject1 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/adesjard/jdeveloper/mywork/SOAApplication/SOAProject1/SOA/SCA-INF/classes

By adding in this additional maven-compiler-plugin execution you will now be able to build projects that contain Spring components and Java source code using Maven.  Unfortunately there is no current workaround for using the Java Embedding activity and building with Maven, so until that bug has been resolved in a future bundle patch it is best to avoid using Java Embedding when possible.