Using Maven with the IBM App Connect Enterprise Toolkit

Use Maven to extend the capability of an integration project by enabling the inclusion of dependencies.

Before you begin

  1. Install and configure Maven. For more information, see https://maven.apache.org/.
  2. Create an application, for example, myMavenApp. For more information, see Creating an application.
  3. Create a message flow that includes a Compute node and add the message flow to your application. For more information, see Creating a message flow and Compute node.

About this task

You can use Maven with a Test project or a Java project. JavaCompute node projects are not supported by Maven.

Procedure

Activate Maven support by completing the following steps:

  1. Add a test case to your message flow by completing the following steps:
    1. Right-click the Compute node and select Create a test case to open the Create test case wizard.
    2. Optionally, edit any fields and select checkboxes as required.
    3. Click Next.
    4. Optionally, edit the package and class detail as required.
    5. Click Next.
    6. Optionally, edit the Java build settings as required.
    7. Click Finish to display the test case in the Java editor of the IBM® App Connect Enterprise Toolkit.
    8. Optionally, edit the Java code as required.

    For more information, see Developing integration tests by using the IBM App Connect Enterprise Toolkit.

  2. Right-click the application and select Configure > Convert to Maven Project to open the Maven POM wizard.
  3. In the Maven POM wizard, accept the default settings and click Finish.
    In the Application Development view of the IBM App Connect Enterprise Toolkit, the letter "M" appears alongside your integration project and alongside the pom.xml file in the Independent Resources section.
  4. Add a dependency by completing the following steps:
    1. In the Other Resources section of the Application Development view, right-click the pom.xml file and select Maven > Add dependency to open the Add dependency wizard.
    2. Enter a value for Group ID. For example, com.google.code.gson.
    3. Enter a value for Artifact ID. For example, gson.
    4. Enter a value for Version. For example, 2.8.6.
    5. Click OK.
    The dependencies are automatically generated and inserted into the pom.xml file:
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>myMavenApp</groupId>
      <artifactId>myMavenApp</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <dependencies>
      	<dependency>
      		<groupId>com.google.code.gson</groupId>
      		<artifactId>gson</artifactId>
      		<version>2.8.6</version>
      	</dependency>
      </dependencies>
    </project>

    For more information about dependencies, see https://maven.apache.org/.

  5. Open the test case that you created in Step 1 and add a test method to enable the Maven dependencies to be included:
    
    @Test
        public void myMavenApp_MavenFlow_Compute_TestCase_002() {
            Gson gson = new Gson();
            System.out.println("My Gson object is "+gson.toString());
            XStream xstream = new XStream();
            System.out.println("xtream object is "+ xstream.toString());   
        }
  6. Errors appear in your integration project after you add the test method to the test case in step 5. Resolve the errors by selecting the imports:
    
    import com.google.gson.Gson
    import com.thoughtworks.xstream.XStreamYour 
    Your integration project is now clean and it contains no errors.

Results

Your integration project is enabled for Maven support.

What to do next

  1. Right-click your integration project and select Run test project. If you configured Maven correctly, the test passes and information about the gson xstream objects is displayed on the console:
    
    mqsicreateworkdir: Copying sample server.config.yaml to work directory
            1 file(s) copied.
    Successful command completion.
    BIP8071I: Successful command completion. 
    2021-03-22 11:15:03.845585: BIP1990I: Integration server 'eclipse-work' starting initialization; version '12.0.0.0' (64-bit) 
    2021-03-22 11:15:03.868357: BIP9905I: Initializing resource managers. 
    2021-03-22 11:15:10.820028: BIP9906I: Reading deployed resources. 
    2021-03-22 11:15:10.838867: BIP9907I: Initializing deployed resources. 
    2021-03-22 11:15:10.842195: BIP2155I: About to 'Initialize' the deployed resource 'myMavenApp' of type 'Application'. 
    2021-03-22 11:15:11.067367: BIP2155I: About to 'Start' the deployed resource 'myMavenApp' of type 'Application'. 
    2021-03-22 11:15:12.355600: BIP2866I: IBM App Connect Enterprise administration security is inactive. 
    2021-03-22 11:15:12.372063: BIP3132I: The HTTP Listener has started listening on port '7600' for 'RestAdmin http' connections. 
    2021-03-22 11:15:12.395      1 this class com.ibm.broker.plugin.MbNonDelegatingJavaResourceClassLoader@3fd9ed70
    2021-03-22 11:15:12.395      1 Attempting Eclipse junit run with args |none -version 3 -port 51241 -testLoaderClass org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader -loaderpluginname org.eclipse.jdt.junit5.runtime -packageNameFile C:\Users\PAULLacy\AppData\Local\Temp\packageNames4957729711074078084.txt  |
    2021-03-22 11:15:12.596      1 runnerClass class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
    2021-03-22 11:15:12.596      1 runnerMainMethod public static void org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(Java.lang.String[])
    2021-03-22 11:15:13.322      1 My Gson object is {serializeNulls:false,factories:[Factory[typeHierarchy=com.google.gson.JsonElement,adapter=com.google.gson.internal.bind.TypeAdapters$29@44d58599], com.google.gson.internal.bind.ObjectTypeAdapter$1@2d8bc790, com.google.gson.internal.Excluder@265a59b8,  ..........
    2021-03-22 11:15:13.674      1 xtream object is com.thoughtworks.xstream.XStream@8a4bee3b
  2. Open the generated bar file called myMavenApp_Testproject.generated.bar in the BAR file editor where you can see the two dependencies that you added plus three dependencies that are needed by xstream. For more information, see BAR file editor.