How to Call Java Class Methods in TIBCO By Adding JAR File: Step By Step Tutorial

In one of my previous tutorials, I explained how we can use Java Code activity to write JAVA Code and execute that in a TIBCO Process. In this Step by Step Tutorial, I am going to explain how we can add our custom JAVA Code’s as a JAR file in our TIBCO project and then how to call Java Class Methods using Java Method activity available in Java Palette.

Step 1: Write Java Class and Create Its JAR file

The first thing that we need to do is to write a Java Class which will be then added to a JAR File. A JAVA class which we want to use in the form of a JAR in our TIBCO project must implement Serializable interface.

In this example case, I am writing a simple JAVA class Student.java with one Main Method and a getAge method as you can see in below code:

package student;

import java.io.Serializable;

public class Student implements Serializable {

public static int getAge() {

return 33;

}

public static void main(String[] args) {

}

}

 

Now you can compile the class and create Its JAR file using the below commands. (I used Netbeans IDE which automatically created the JAR file once I built the project).

To compile Student.java file to make a .class file, write the following command in the command prompt:

javac Student.java

This will create Student.Class file in the same directory where you have Student.java file.

Now in order to create the JAR file, write the following command in the command prompt:

jar cvf Student.jar Student.Class

This will create a jar file named Student.jar in the same directory.

Please note that if you create a JAR file with a higher Java Version and your TIBCO installation has a lower JAVA version, class and its methods of the JAR file will not appear in your TIBCO project. Make sure that your jar is created using same JAVA version or a lower version.

Note: If you are using Netbeans IDE, the JAR file which gets created automatically when you build the project will be in the dist folder of the project.

 

Step 2: Add JAR to the TIBCO BW Project

Once we have created a JAR File, we need to add it to our TIBCO project. In the TIBCO designer project, add a new AliasLibrary from the General Palette.

In the Aliases Tab of this activity, browse and add Student.jar file as you can see in the screenshot below:

tibco add jar to alias library

 

Now, this JAR file will be available in our project and we can call the methods from the class enclosed in this jar file.

 

Step 3: Call Java Method from a jar file using TIBCO Java Method activity

Create a TIBCO Designer Process and add Java Method activity from the Java Palette. In the configuration of this activity, choose the AliasLibrary. Then use the class browser option in front of Class field so that all the JARs are shown. As you can see in the screenshot below; Student.jar is also available and we can choose Its class methods:

tibco select method from a class in jar

 

 

After selecting the class and Its method, complete configuration of Java Method activity will look like below:

tibco java method configuration

 

As getAge() method of our java class requires no input parameter, we don’t need to go to the Input tab of Java Method activity in this case.

Simply validate the process and once Its validated successfully, proceed to next step in which we will test how we can call and run java class method of a jar file from our TIBCO process.

 

Step 4: Run Java Class Method from a JAR file using TIBCO Java Method Activity

Load the process in designer tester and run it. As you can see in the screenshot below, code has run successfully and our java method has returned the result based on the implementation in the java class:

tibco java method output

 

 

Ajmal Abbasi

Ajmal Hussain Abbasi is Integration Consultant By Profession with 13+ years experience in Integration domain mainly with TIBCO products. He has extensive practical knowledge of TIBCO Business Works, TIBCO Cloud, TIBCO Flogo, TIBCO Mashery, TIBCO Spotfire, EMS and TIBCO ActiveSpaces. He has worked on a number of highly critical integration projects in various sectors by using his skills in TIBCO Flogo, TIBCO API Management (Mashery), TCI, Tibco Designer, TIBCO Business Studio, Adapters, TIBCO EMS, RV, Administrator, TIBCO BE, TIBCO ActiveSpaces etc. Ajmal Abbasi has experience with MuleSoft ESB as well. Ajmal Abbasi is also experienced in the area of API Management particularly with WSO2 API management platforms. Ajmal Abbasi is also experienced in developing solutions using Core Java and J2EE Technologies. You can contact Ajmal Abbasi for Consultancy, Technical Assistance and Technical Discussions.

More Posts - Website - Facebook - LinkedIn - YouTube

7 thoughts on “How to Call Java Class Methods in TIBCO By Adding JAR File: Step By Step Tutorial

  1. Augusto Cesar

    Hi friend, your blog is great, I’m learning BW here in Brazil and I’m practicing through your post. Thanks!!!

    Reply
  2. Pingback: 15 Most Popular TIBCO Tutorials on TutorialsPedia | TutorialsPedia

  3. narscia

    Hi Ajmal

    May you please create a simple example of a java class method that requires an input, because I’m getting null exceptions on mine

    Thank you

    Reply
  4. kaurm

    Hi Ajmal,
    Your posts are really very helpful. Thanks for sharing knowledge 🙂
    I have one question.
    Suppose there are 10-12 design time libraries in one project. When I am opening this project on some other system I have to import these libraries one by one. I know there is one way to import one properties in Preferences using file aliases but i dont know how to create that file.
    Could you please provide a tutorial for the same. It will be of so much help.

    Thanks a lot.

    Reply
    1. Ajmal Abbasi Post author

      Dear Kaurm,

      You can use Edit–>Preferences–>File Aliases–>Export option to export all aliases in a .properties file and then can import it in any system where you will be opening the project. However, the properties file will have the absolute paths to the libraries in the machine where it was exported so you will have to modify the file to point to the right paths before importing. Thanks

      Reply
  5. Noel

    HI Ajmal,

    How would you reference this jar in a JAVA Code activity ?
    What would be the path for the import statement to reference this newly created jar correctly?

    Thanks,
    Noel

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *