Maven 用のネイティブ COBOL プロジェクトの構成

Pre-requisite: 必要なリソースを Maven リポジトリにインストールするには、通常版の Maven がインストールされて PATH にある必要があります。
COBOL JVM プロジェクトとは異なり、ネイティブ COBOL プロジェクトおよびネイティブ単体テスト プロジェクトは、Maven ベースのライフサイクルに組み込むために Maven ベースのプロジェクトに変換する必要はありません。代わりに、pom.xml ファイルを手動で追加し、Ant ベースのビルド プロセスのラッパーとして機能する maven-antrun-plugin 用に構成します。
  1. Enterprise Developer コマンド プロンプトから、いくつかの追加の依存関係を Maven リポジトリにインストールします。
    注: これらのサブステップは、一度だけ実行する必要があります。Enterprise Developer の一部として提供される必要な .jar ファイルを Maven リポジトリに含めることで、それらを後続のネイティブ COBOL プロジェクトおよびネイティブ単体テスト プロジェクトで利用できます。
    1. 次の環境変数を設定します。
      set COBDIR=C:\Program Files (x86)\Micro Focus\Enterprise Developer
      set COBOL_VERSION=8.0.0
      注: 製品をデフォルト以外のディレクトリにインストールした場合は、それに応じてパスを調整してください。
    2. mfant.jar を Maven リポジトリにインストールします。
      mvn install:install-file -Dfile="%COBDIR%\bin\mfant.jar" -DgroupId=com.microfocus.cobol.build -DartifactId=mfant -Dversion=%COBOL_VERSION% -Dpackaging=jar
      ビルドが成功すると、mfant.jar が Maven リポジトリ (デフォルトでは %USERPROFILE%\.m2) にインストールされます。
  2. POM ファイルをネイティブ COBOL プロジェクトに追加します。
    1. COBOL エクスプローラーで、必要なプロジェクトを右クリックし、[New] をポイントして [File] を選択します。

      [Create New File] ダイアログ ボックスが表示されます。

    2. [File name] フィールドに pom.xml と入力し、[Finish] をクリックします。

      ファイルがエディターで開きます。

  3. プロジェクトで使用できるように pom.xml を編集します。
    1. ファイルを POM として識別するベース タグを追加し、例の成果物の詳細を必要に応じて修正します。
      <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. <build> セクションの前に <properties> セクションを挿入します。
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.output.dir>${project.basedir}/New_Configuration.bin</project.output.dir>  
       </properties>
    3. 次のプロパティを更新し、例で指定されている後半部分の値を置き換えます。
      プロパティ 説明
      <project.output.dir> プロジェクトの出力ディレクトリ。
    4. <build> タグの間にフェーズ/ゴールおよび依存関係の詳細を追加します。
      <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. Ctrl + S を押してファイルを保存します。
    プラグインが正常にインストールされ、pom.xml で依存関係として正しく参照されると、プロジェクトをビルドし、想定されるビルド成果物を生成できるようになります。
  4. エディターで POM ファイルを右クリックし、[Run As > Maven install] を選択します。 ビルドが呼び出され、ビルドの結果が <project.output.dir> に表示されます。
ここで作成したものと同様のサンプル POM ファイルが「POM ファイルの例」に用意されています。