Configuring a native COBOL project for Maven

Pre-requisite: To install the required resources into your Maven repository, you will need a full version of Maven installed and on the PATH.
Unlike COBOL JVM projects, native COBOL and native Unit Testing projects are not required to be converted to Maven-based projects to be incorporated into your Maven-based lifecycles; instead, you manually add a pom.xml file and configure it for the maven-antrun-plugin, which acts as a wrapper around your Ant-based build processes.
  1. From a Visual COBOL command prompt, install some additional dependencies into your Maven repository:
    Note: These substeps are only required to be run once. When the required .jar files, which are supplied as part of Visual COBOL, are part of your Maven repository, you can utilize them with subsequent native COBOL and native unit testing projects.
    1. Set the following environment variables:
      export COBDIR=/opt/microfocus/VisualCOBOL/bin/cobsetenv
      export COBOL_VERSION=8.0.0
      Note: If you have installed your product into a non-default directory, adjust the path accordingly.
    2. Install mfant.jar into your Maven repository:
      mvn install:install-file -Dfile="$COBDIR/lib/mfant.jar" -DgroupId=com.microfocus.cobol.build -DartifactId=mfant -Dversion=$COBOL_VERSION -Dpackaging=jar
      After a successful build, mfant.jar is installed in your Maven repository ( /home/user-name/.m2, by default).
  2. Add a POM file to your native COBOL project:
    1. From COBOL Explorer, right-click the required project, point to New and select File.

      The Create New File dialog box is displayed.

    2. In the File name field, type pom.xml, and then click Finish.

      The file is opened in the editor.

  3. Edit the pom.xml to work with your project:
    1. Add the base tags to identify the file as a POM, and then amend the example artifact details, as appropriate:
      <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.mfcobolbook.cobol</groupId>
       <artifactId>MyMavenProject</artifactId>
       <version>1.0.0</version>
       <build>
       </build>
      </project>
    2. Before the <build> section, insert the <properties> section:
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.output.dir>${project.basedir}/New_Configuration.bin</project.output.dir>  
       </properties>
    3. Update the following properties, substituting the later part of the example value given:
      Property Description
      <project.output.dir> The output directory for your project.
    4. Within the <build> tags, add the phases/goals, and dependency details:
      <plugins>
       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>3.0.0</version>
          <executions>
           <execution>
            <id>build</id>
              <phase>compile</phase>
               <configuration>
                <target>
                  <ant antfile="${project.basedir}/.cobolBuild" target="cobolbuild" />
                </target>
               </configuration>
               <goals>
                <goal>run</goal>
               </goals>
            </execution>
            <execution>
             <id>clean</id>
             <phase>clean</phase>
              <configuration>
               <target>
                <ant antfile="${project.basedir}/.cobolBuild" target="clean" />
               </target>
              </configuration>
              <goals>
               <goal>run</goal>
              </goals>
            </execution>
           </executions>
           <dependencies>
            <dependency>
             <groupId>ant-contrib</groupId>
             <artifactId>ant-contrib</artifactId>
             <version>1.0b3</version>
             <exclusions>
              <exclusion>
               <groupId>ant</groupId>
               <artifactId>ant</artifactId>
              </exclusion>
             </exclusions>
            </dependency>
            <dependency>
              <groupId>com.microfocus.cobol.build</groupId>
              <artifactId>mfant</artifactId>
              <version>8.0.0</version>
             </dependency>
            </dependencies>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-install-plugin</artifactId>
           <version>3.0.0-M1</version>
           <configuration>
            <skip>true</skip>
           </configuration>
         </plugin>
        </plugins>
    5. Press Ctrl + S to save the file.
    When the plugins are successfully installed and correctly referenced as dependencies in the pom.xml, you can now build the project and produce the expected build artefacts. .
  4. Right-click the POM file in the editor, and select Run As > Maven install. A build is invoked and the results of the build are shown in <project.output.dir>.
A sample POM file, similar to the one just created, is available from Example POM file.