Monday, August 1, 2011

How to call a Java method inside a BPEL process using Java activity

Inside a BPEL process we can call a Java class to use any of its methods. This helps in reusing the Java code from existing projects or sometimes doing things in Java which are still not possible in BPEL

This is a 2 step process

Create a .jar file of the Java project

1.) Below is the screen shot of the Java class which we want to use in our BPEL process.

2.) Create a JAR file of this Java project.

Right click on the Java project and select New

Now select the Deployment Profile under General and select JAR File under Items.

Give the Name to Jar file "HelloWorldJava"

Click on OK, and then right click on the project folder and deploy it.
This will create a .jar file of this java project.

This HelloWorld.Jar goes inside the deploy folder of this project by default.

Use java class from the .jar file inside the BPEL process

Create a new SOA composite and drop a BPEL process inside composite.xml , Copy the HelloWorldJava.jar which we just created in the presious steps inside the Composite "SCA-INF/lib" folder.

Now drop a Java Embedding activity inside the BPEL process.

Inside the Java Embedding use the below code

** If there is any error just typecast it to string.

We need to do 2 things here first include the Jar in the project and then use import statement to use those classes inside the BPEL

1.) To include the JAR in the project, double click on the project to open the project properties click on "Libraries and class path" now click "Add JAR/Directory.." and include the jar file which we have placed inside the SCA-INF/lib folder of the same project.

2.) Use Import statement inside the BPEL source code, inside the BPEL process we have to manually use Import statement to import the java class in order to use the class inside the BPEL.

Create a new variable "Greeting" of String type, inside the Java code we are passing the output of the java method to this variable, this will bring the output of the java to BPEL process.

Use a Assign activity to map the Greeting variable to output variable.

Deploy and test.


Audit Flow

The Java activity is still not that advance to give developer error details, the exceptions thrown are very confusing, if the above steps are followed life can be little easy when Java activity is used.

Steps for using Java activity

1.) Creating JAR from JDEV
2.) Copy the JAR in the same projects SCA-INF/lib folder
3.) Include the JAR by going to "Libraries and class path".
4.) Use Import statement inside the source code of BPEL, make sure that all the import statement are included for what ever code is written inside the java acitvity, there is change in the package structure of various existing classes which are used inside 10G and 11G
example : For Java class Base64Decoder the import statement differ in 10G and 11G

10G "com.collaxa.common.util.Base64Encoder"
11G "oracle.soa.common.util.Base64Encoder"


  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    Vee Eee Technologies| Vee Eee Technologies

  2. Hi, thanks for excellent post. I have followed exactly the steps written, but getting deployment error: failed to compile execlets of BPEL. Maybe the reason is the import in BPEL source code. I have used import="java_packet_name.class_name" , is this correct?

  3. Hi Lucia,

    Use syntax as in the print screen bpel:exec,
    Make sure that the java code is correct.


  4. Thanks Yatan... good article. Helps a lot

  5. Hi Yatan, Is there any way we can pass the variable value to the Java, instead of hard-coding? If yes, how to do that?

  6. This is great stuff, thanks. Was Googling away and came across this as I couldn't quite figure out how to package the JAR - tried lib/ to no avail. SCA-INF/lib did the trick.

    A perhaps better way to achieve the same thing (if you continuously update the library to be packaged inside SCA-INF/lib) is to do the following:
    1. Create a dependency to your library project on your SCA project (HelloWorldJava - NOT Output as that just packages up classes in SCA-INF/classes)
    2. On your SCA project edit the Deployment profile (SOA-SAR File), under File Groups add a new File Group "SCA-INF lib", set Target Directory in Archive to: SCA-INF/lib, in Contributors tick the HelloWorldJava library

    Now, every time you amend HelloWorldJava and want to deploy your SCA it will be done automatically - rather than you having to copy the library every time.

    Hope this helps someone else...

  7. hi Yatan..,

    Can u tell me how to use BPEL embedded activity for File download
    As iam using UCm. I need to read the file from UCM server. Downlaod it and should show it in ADF UI.


  8. <bpelx:exec import="MyClass.*"/>
    I can not use.
    Error(78): Element 'exec' not expected.
    I use bpel proces 2.0

    1. I have the same question. Can you please provide answer if you have.

  9. Instead of keeping the JAR in the same projects SCA-INF/lib folder, please can you suggest how to keep this jar at a common location and refer it in multiple SOA project?

  10. Hi Prashant,

    Were you able to get any solution for your question; keeping the jar at a common location..

    Thanks, varun

  11. Hi,

    can someone help me how to resolve this error message ?

    "[10:33:18 PM] Error deploying archive sca_Job2_UnzipAndMoveToUnzipped_rev1.0.jar to partition "default" on server soa_server1 []
    [10:33:18 PM] HTTP error code returned [500]
    [10:33:18 PM] Error message from server:
    There was an error deploying the composite on soa_server1: Deployment Failed: Error occurred during deployment of component: BPELProcess_Unzip to service engine: implementation.bpel, for composite: Job2_UnzipAndMoveToUnzipped: ORABPEL-05250

    Error deploying BPEL suitcase.
    error while attempting to deploy the BPEL component file "H:\Oracle\Middleware\user_projects\domains\Dev_Acorde\servers\soa_server1\dc\soa_93e44a15-0069-44e1-ae1a-5fc4586e430c"; the exception reported is: java.lang.RuntimeException: failed to compile execlets of BPELProcess_Unzip"

    Here is my original code:

    I imported the JAR file to the project properties and placed the jar file to SCA-INF\lib folder. I am still getting the same error.

    Harisudhan Selvaraj

  12. HI I followed the same steps. But i am facing below mentioned exception.Kinldy help me out of this

    A fault occurred while invoking the webservice operation. The fault is :
    Could not initialize class com.invoice.InvoiceDocument

    java.lang.NoClassDefFoundError: Could not initialize class com.invoice.InvoiceDocument
    at orabpel.generateinvoicebpel_ws.ExecLetBxExe0.execute(
    at com.collaxa.cube.engine.ext.bpel.common.wmp.BPELxExecWMP.__executeStatements(
    at com.collaxa.cube.engine.ext.bpel.common.wmp.BaseBPELActivityWMP$
    at com.collaxa.cube.engine.ext.bpel.common.wmp.BaseBPELActivityWMP$
    at com.collaxa.bpel.sws.SWSComponentProcessActivityWrapper$
    at com.collaxa.bpel.sws.SWSCallableActivityWrapper.execute(
    at com.collaxa.bpel.sws.SWSComponentProcessActivityWrapper.execute(
    at com.collaxa.cube.engine.ext.bpel.common.wmp.BaseBPELActivityWMP.perform(
    at com.collaxa.cube.engine.CubeEngine.performActivity(

    oracle.sysman.emInternalSDK.webservices.util.SoapTestException: Client received SOAP Fault from server : Could not initialize class com.invoice.InvoiceDocument


  13. I can not use.
    Error(78): Element 'exec' not expected.
    I use bpel proces 2.0