Creating Java code for a JavaCompute node

You can associate Java™ code with your JavaCompute node by using a wizard, setting node properties, or creating a Java project.

Before you begin

Before you complete this task, create a JavaCompute node in your message flow.

About this task

You can store the Java code for a JavaCompute node in the same application as the message flow that contains the JavaCompute node. Alternatively, if you want to share Java classes across multiple solutions, you can store Java code in a shared library and refer to that library from one or more applications that contain message flows with JavaCompute nodes. In this case, if you already have Java classes, you can add them to a shared library before you create your message flows. Alternatively, you can specify a shared library to contain the classes when you create the JavaCompute node.

Use the New Java Compute Node Class wizard to create template code

About this task

Use the New Java Compute Node Class wizard to create template code.

Procedure

  1. In the IBM® App Connect Enterprise Toolkit, right-click the JavaCompute node and click Open Java.
  2. Follow the instructions in the New Java Compute Node Class wizard.
    1. On the Java Compute Node Class page, set Source folder to the application or library that contains the Java classes. Click Next.
    2. On the Java Compute Node Class Template page, choose one of the following options:
      • For a filter node template, select Filtering message class.
      • To change an incoming message, select Modifying message class.
      • To create a new message, select Creating message class.
      • To process messages by using the JAXB template, select Process via JAXB class. If you want to use the Generate JAXB Java object classes wizard to create your JAXB Java object classes, or to update the template code to reference your existing JAXB Java object classes, click Next. For more information, see Creating JAXB Java object classes by using a wizard.
      • To execute business rules, select Process via Operational Decision Manager ruleset. If you want to use the wizard, click Next.
    3. Optional: If necessary, change the default Java build settings. Click Next.
    4. Optional: If necessary, change the default JavaCompute node project name.
  3. Click Finish.

Results

The Java class file opens in the editor. If you view the basic properties for the JavaCompute node, the Java class field is populated with the location of the specified Java class. If your Java classes are stored in a shared library, the Java classloader service field contains a qualifier for the shared library that contains the Java class in the form {sharedLibraryName}.

Associate a JavaCompute node with an existing Java class

About this task

You can associate a JavaCompute node with an existing Java class that the wizard has generated previously. You can use this method to share the same Java code between multiple nodes.

To associate a JavaCompute node with an existing Java class, complete the following steps:

Procedure

  1. In the IBM App Connect Enterprise Toolkit, right-click the JavaCompute node and click Properties.
  2. In the Java Class field, click Browse and start to type the name of the required Java class.
    As you type, matching classes are displayed.
  3. Select the appropriate class and click OK.

Results

The Java class field is populated with the location of the specified Java class. If your Java classes are stored in a shared library, the Java classloader service field contains a qualifier for the shared library that contains the Java class in the form {sharedLibraryName}. View the Java class by double-clicking the JavaCompute node.

Create a Java project from scratch

About this task

You can create a Java project from scratch. Before you add one or more classes to the project, complete the following steps.

Procedure

  1. Open the .project file in the text editor, and ensure that the following builders and natures are set:
    <buildSpec>
    		<buildCommand>
    			<name>org.eclipse.jdt.core.javabuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    		<buildCommand>
    			<name>com.ibm.etools.mft.java.builder.javabuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    		<buildCommand>
    			<name>com.ibm.etools.mft.jcn.jcnbuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    		<buildCommand>
    			<name>com.ibm.etools.mft.bar.barbuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    	</buildSpec>
    	<natures>
    		<nature>org.eclipse.jdt.core.javanature</nature>
    		<nature>com.ibm.etools.mft.bar.barnature</nature>
    		<nature>com.ibm.etools.mft.jcn.jcnnature</nature>
    	</natures>
    
  2. Add the following plug-ins to the build path of the Java project:
    1. Open the properties of the Java project.
    2. Select Java Build Path and open the Libraries tab.
    3. Click Add Variable.
    4. Select the variable JCN_HOME and click OK.
    5. Double-click the variable you added to open the Edit Variable Entry dialog.
    6. Click Extension and select javacompute.jar.
    7. Repeat the previous four steps to add the variable JCN_HOME/jplugin2.jar.
  3. Create the appropriate Java class and ensure that it extends from com.ibm.broker.javacompute.MbJavaComputeNode.

Results

You have created your Java project.

What to do next