Saturday, July 19, 2008

How to deploy Java Classes with BPEL Process

While implementing a business process using BPEL, sometimes it is required to use Java to implement a functionality required by a business process. You can embed your Java code in BPEL process using Java embedding activity provided by Oracle BPEL. If your Java code is of few lines you can paste it inside the Java embedding editor and you can manage it but if you are planning to implement a functionality which requires lines of code, it is better to create java classes inside your BPEL Process Project. You can leverage JDeveloper’s Java editor to write and manage Java code.

You can import Java classes in the BPEL process using <bpelx:exec import....>. If you deploy the BPEL process from JDeveloper it compiles the Java code and bundle required classes and libraries inside the BPEL suitcase. You can use JDeveloper to deploy your processes on the development server. To deploy a business processes on Test/Performance/Production servers its better to use deployment scripts, because its not wise to modify endpoint URL and other connectivity information manually for each server in your BPEL process project and deploy it.

Using deployment scripts you can
  • Customize WSDL/XSL/XSD end-point locations.
  • Customize JNDI address of Data source/JMS Queue or Topics.
  • Checkout latest code from SVN/CVS/VSS repositories.
  • Deploy BPEL/ESB/Java on the development/test/performance/production environments.

JDeveloper generates an ant build script for each BPEL process project, it uses ant script to build and deploy business process. If your BPEL process is using java classes and you would deploy it from JDeveloper the process will be deployed successfully. All the Java classes and required libraries will be bundled in BPEL-INF folder of the BPEL suitcase.

If you try to execute the same script from the command prompt it will throw an exception like the one given below:

Java compilation failed.
Failed to compile file(s) "HelloWorldProcess.bpel".
Exception reported is: HelloWorldProcess.bpel:3: Class build.test.HelloWorld not found in import.import build.test.HelloWorld;

If you see the deployment script it does not have an ant task to compile java code. It works in JDeveloper because JDevloper compile the java classes first and then executes this script so the bpelc task is able to find the required Java classes. To make this script work from command prompt you need to do the following:

• Add a task to compile the java classes.

<target name="compileJava" description="Compile Java files">
Compiling java files
<javac destdir="${process.dir}/output" encoding="UTF-8" source="1.5" target="1.5">
<src path="${src}"/>
<mkdir dir="${process.dir}/lib"/>
<jar destfile="${process.dir}/lib/${bpel.classes.jar}">
<fileset dir="${process.dir}/output"/>

• Modify target "compile" and add dependency for target "compileJava".

<target name="compile" depends="compileJava">
• Modify the bpelc task to add classpath for the compiled java classes so bpelc will be able to find the required classes.
<bpelc input="${process.dir}/bpel/bpel.xml" out="${process.dir}/output"
rev="${rev}" home="${bpel.home}" classpath="${env.classpath};${process.dir}\output">

• As some libraries are business process specific, you want to keep them inside the BPEL suitcase rather then adding them to shared libraries or copying to <ORASOA_HOME>/j2ee/home/applib folder. If you copy the libraries to applib folder or add to shared libraries by modifying server.xml you need to bounce the SOA server. To copy the BPEL process specific dependency jars and the classes in the BPEL-INF folder of BPEL suitecase, you need to add <lib> tag in the bpelc task:

<bpelc input="${process.dir}/bpel/bpel.xml" out="${process.dir}/output"
rev="${rev}" home="${bpel.home}" classpath="${env.classpath};${process.dir}\output">
<lib dir="${process.dir}/lib" includes="bpelclasses.jar"/>
<lib dir="${bpel.lib}" includes="**/*.jar"/>

Save the build script and execute it from command prompt, don’t forget to set username/password for SOA suite and all other environment related properties in