Integrating Maximo with Java application through RMI

This entry is part of the Maximo Java Development series.

In this article I will describe how to call Maximo business objects methods remotely using a Java RMI connection. This technique can be useful to integrate Maximo in custom applications written in Java or to perform a particular processing of data stored in Maximo database using an external application.
For simplicity I will describe how to create a sample Java project using Eclipse to print the list of assets. However, this technique can be used in any Java application.
First of all you have to copy some jar files from the Maximo server to your development system. Go in the application deployment directory (e.g. WebSphere\AppServer\profiles\ctgAppSrv01\installedApps\ctgCell01\MAXIMO.ear) and copy the businessobjects.jar file and the entire lib directory.
Launch Eclipse, create an empty Java project and add the businessobject.jar and icu4j.jar files to the project classpath. Your project should look like this.


Now create an empty class named com.maximodev.MxRemoteConnection and paste the following code into it.

package com.maximodev;

import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.util.MXSession;

public class MxRemoteConnection
{
 
  /**
  * Sample main method to connect to Maximo server and list all the assets
  */
  public static void main(String[] args) throws Exception
  {
    MXSession session = getConnection("192.168.18.128", 13400, "MXServer", "maxadmin", "maxadmin");

    MboSetRemote assetMboSet = session.getMboSet("ASSET");
    assetMboSet.setOrderBy("ASSETNUM");
 
    MboRemote assetMbo;
    for(int j=0; ((assetMbo = assetMboSet.getMbo(j)) != null); j++)
    {
      String assetNum = assetMbo.getString("ASSETNUM");
      String location = assetMbo.getString("LOCATION");
      String desc = assetMbo.getString("DESCRIPTION");
      System.out.println(assetNum + " - " + location + " - " + desc);
    }    
  }

  private static MXSession getConnection(String host, int rmiPort, String serverName, String user, String pwd)
  {
    MXSession session = MXSession.getSession();

    String connHost = host + ":" + rmiPort + "/" + serverName;
    System.out.println("Connecting to " + connHost);

    session.setHost(connHost);
    session.setUserName(user);
    session.setPassword(pwd);

    try
    {
      session.connect();
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return null;
    }
    System.out.println("Connection OK");

    return session;
  }
}

Update the parameters passed to the getConnection method in the first line of the main method according to your environment.

Now run the Java application and it will (hopefully) connect to you Maximo/TPAE server and list all your assets. If you are having problems finding the correct settings, you may try to test RMI connection using the checkmxserver utility in [SMPDIR]\maximo\tools\maximo\internal directory.

Apart from the getConnection method the previous code snippet is very similar to any Maximo MBO Java code. The only relevant difference is in the following line of code.

MboSetRemote assetMboSet = session.getMboSet("ASSET");

This means you have to use the MXSession object to retrieve the first MboSet. After that you can use the same identical APIs used in standard MBO development.

Labels: , ,