寝て起きて寝る

過ぎたるは及ばざるが如し

Mavenを利用してWebLogic12cへデプロイしてみた

今さらですが、Mavenを利用してWeblogic12cへデプロイする為のMavenの設定方法などのメモです

weblogic-maven-pluginプラグインのインストール

ローカルにWebLogicをインストールしている場合

1. Oracle Maven同期プラグインのインストール

ディレクトリを${ORACLE_HOME}\oracle_common\plugins\maven\com\oracle\maven\oracle-maven-sync\12.2.1へ移動し下記を実行します。 (WebLogic Server 12.2.1 の場合)

$ mvn install:install-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar
2. ローカルにあるモジュールをローカルレポジトリに取り込む
$ mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=${ORACLE_HOME}

ローカルにWebLogicをインストールしていない場合

ローカルにWeblogicをインストール指定に場合は、Oracle Mavenリポジトリから必要なモジュールを取得する。

1. Oracle OTN Account の作成

Oracle Mavenリポジトリにアクセスするのに必要ですので事前に作成します。 www.oracle.com

2. 必要な接続情報等の設定を行う

リポジトリプラグインリポジトリの設定をpom.xmlもしくはsetting.xmlへ、認証情報をsetting.xmlへ下記の様に記述します。

pom.xml or setting.xml

  <repositories>
    <repository>
      <id>maven.oracle.com</id>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <url>https://maven.oracle.com</url>
      <layout>default</layout>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>maven.oracle.com</id>
      <url>https://maven.oracle.com</url>
    </pluginRepository>
  </pluginRepositories>

setting.xml

  <servers>
    <server>
      <id>maven.oracle.com</id>
        <username>xxxxxxxxxxxxxxxxxxxxxxxx</username>
        <password>xxxxxxxxxxxxxxxxxxxxxxxx</password>
      <configuration>
        <basicAuthScope>
          <host>ANY</host>
          <port>ANY</port>
          <realm>OAM 11g</realm>
        </basicAuthScope>
        <httpConfiguration>
          <all>
            <params>
              <property>
                <name>http.protocol.allow-circular-redirects</name>
                <value>%b,true</value>
              </property>
            </params>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
  </servers>

usernameやpasswordはmavenの機能でmvn --encrypt-master-passwordmvn --encrypt-passwordを利用して暗号化できます。

WebLogic プラグインの追加

下記の様にpom.xmlへ記述しWebLogic Pluginの追加をします。

<build>
    <plugins>
      <plugin>
        <!-- This is the configuration for the weblogic-maven-plugin -->
        <groupId>com.oracle.weblogic</groupId>
        <artifactId>weblogic-maven-plugin</artifactId>
        <version>12.2.1-0-0</version>
        <configuration>
         <middlewareHome>/fmwhome/wls12210</middlewareHome>
        </configuration>
        <executions>
          <!-- Execute the appc goal during the package phase -->
          <execution>
            <id>wls-appc</id>
            <phase>package</phase>
            <goals>
              <goal>appc</goal>
            </goals>
            <configuration>
             <source>${project.build.directory}/${project.name}.${project.packaging}</source>
            </configuration>
          </execution>
          <!-- Deploy the application to the WebLogic Server in the pre-integration-test phase -->
          <execution>
            <id>wls-deploy</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <!--The admin URL where the app is deployed. Here use the plugin's default value t3://localhost:7001-->
              <adminurl>t3://127.0.0.1:7001</adminurl>
              <user>weblogic</user>
              <password>password</password>
              <!--The location of the file or directory to be deployed-->
              <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
              <!--The target servers where the application is deployed. Here use the plugin's default value AdminServer-->
              <targets>AdminServer</targets>
              <verbose>true</verbose>
              <name>${project.build.finalName}</name>
            </configuration>
          </execution>
          <!-- Stop the application in the pre-integration-test phase -->
          <execution>
            <id>wls-stop-app</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>stop-app</goal>
            </goals>
            <configuration>
              <adminurl>t3://127.0.0.1:7001</adminurl>
              <user>weblogic</user>
              <password>password</password>
              <name>${project.build.finalName}</name>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build> 

WebLogic12cへデプロイ

下記のコマンドでデプロイします。

mvn com.oracle.weblogic:weblogic-maven-plugin:deploy

その他にもコマンドがあります。 docs.oracle.com

Oracle Mavenリポジトリを使用する場合は、初回実行時はWebLogicのモジュール情報を取得するので時間がかかります。 また2回目移行もモジュール情報のチェック?を行うので時間がかかります。 その場合は、-oを指定してオフラインモードで実行します。

参考サイト