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:

ORABPEL-00017
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">
<echo>
--------------------------------------------------------------
Compiling java files
--------------------------------------------------------------
</echo>
<javac destdir="${process.dir}/output" encoding="UTF-8" source="1.5" target="1.5">
<src path="${src}"/>
</javac>
<mkdir dir="${process.dir}/lib"/>
<jar destfile="${process.dir}/lib/${bpel.classes.jar}">
<fileset dir="${process.dir}/output"/>
</jar>
</target>

• 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"/>
</bpelc>

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 build.properties.


8 comments:

Unknown said...
This comment has been removed by a blog administrator.
Matthew Shoemaker said...

Thanks for this information. I have it ALMOST working. When I build my process through jDev the resulting jar is 115KB, and inside the BPEL-INF directory has a lib directory that contains bpelclasses.jar. When I use the ant script my resulting jar is 72KB and has absolutely nothing inside the BPEL-INF directory. Any suggestions?

Matthew Shoemaker said...

Ah, never mind I think I got it. I failed to add this line:

"%lib dir="${process.dir}/lib" includes="bpelclasses.jar"/%"

to my bpelc action.

Adinda Setyo Bhaning said...

can i have your e-mail, sir? i'm a newbie in SOA, and got dizzy 'bout it because i'd like to take SOA as my thesis. need your help, sir. thank you very much.

regards,
dinda-indonesia

Unknown said...

Also it might be the issue of classpath, maybe the classpath doesn't contains the needed jars, such as the aia.jar. I met the same exception, but it caused by the lack of aia.jar

ayshwariya said...

http://itis-consultants.blogspot.in/2010/03/java-training-course-to-pass-scjp-6-in.html

ganesh said...

Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.


Java Training Courses

Unknown said...

very good infromation and thanks for sharing this keepitup.
JAVA Online Tutorials