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

By | August 23, 2014

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 a TIBCO Consultant By Profession with more than 6 years experience in TIBCO products. He has extensive practical knowledge of TIBCO Business Works, TIBCO Spotfire, TIBCO BE, EMS and TIBCO ActiveSpaces. He has worked on a number of highly critical integration projects in Telecom sector by using his skills in Tibco Designer, Adapters, TIBCO EMS, RV, Administrator, TIBCO BE, TIBCO ActiveSpaces etc. Ajmal Abbasi is also experienced in developing solutions using Oracle PL/Sql, Linux and Java. You can contact Ajmal Abbasi for Consultancy, Technical Assistance and Technical Discussions.

More Posts - Website - Facebook - LinkedIn

4 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

Leave a Reply

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