0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring Bootでmaven install時にWildfly設定ファイルを追加する方法

Posted at

00. 前提

やりたいこと

Wildflyの設定ファイルをwarの指定した場所に追加したい
・jboss-web.xml ・・・ 設定ファイル

環境

・言語:Java8
・FW:Spring Boot
・Webサーバー:Wildfly
・エディター:Spring Tool Suite

展開後の構成

*.war
├─META-INF
└─WEB-INF
  jboss-web.xml
  ├─classes
  └─lib

1. pom.xmlを編集する

以下の通りpom.xmlを修正

<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>*.*.*</modelVersion>
  
  <groupId>***</groupId>
  <artifactId>***</artifactId>
  <version>***</version>
  <packaging>war</packaging>
  <!-- <url>http://maven.apache.org</url> -->
  
  <name>***</name>
  <description>***</description>

  <parent>
    ***
  </parent>

  <properties>
    ***
  </properties>

  <dependencies>
    ***
  </dependencies>
  <!-- ★ここから★ -->
  <build>
	<finalName>***</finalName>
    <!-- プラグインの設定 -->
    <plugins>
      <plugin>
        <groupId>***</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <!-- 設定ファイル -->
            <resource>
            <!-- 設定ファイルの保存場所 -->
              <directory>${basedir}/xml</directory>
              <filtering>true</filtering>
            <!-- 設定ファイルの出力先 -->
              <targetPath>WEB-INF</targetPath>
            <!-- 対象ファイル名 -->
              <includes>
                <include>**/jboss-web.xml</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <!-- ★ここまで★ -->
</project>

補足.1

設定ファイルの保存場所と指定方法は以下の通り

<!-- 設定ファイルの保存場所 -->
<directory>${basedir}/xml</directory>

${basedir}
├─src
├─lib
├─maven
└─xml
   jboss-web.xml
 pom.xml

補足.2

出力先はtargetPathで指定する

※ WEB-INFの場合

<targetPath>WEB-INF</targetPath>

※ META-INFの場合

<targetPath>META-INF</targetPath>

補足.3

他に追加したいXMLが存在する場合はpluginsタグ内に追加する

    <plugins>
      <plugin>
        ***
      </plugin>
      <!-- ★ここから★ -->
      <plugin>
        <groupId>***</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <!-- 設定ファイル -->
            <resource>
            <!-- 設定ファイルの保存場所 -->
              <directory>${basedir}/xml</directory>
              <filtering>true</filtering>
            <!-- 設定ファイルの出力先 -->
              <targetPath>WEB-INF</targetPath>
            <!-- 対象ファイル名 -->
              <includes>
                <include>**/jboss-web.xml</include>
              </includes>
            </resource>
          </webResources>
        </configuration>
      </plugin>
      <!-- ★ここまで★ -->
    </plugins>

02. warファイルの生成

02-01. maven clean

対象のプロジェクトを選択して、「実行」→「maven clean」

02-02. maven install

対象のプロジェクトを選択して、「実行」→「maven install」
以下のパスにwarファイルが生成されている
${basedir}
├─src
├─lib
│ commons-lang3-3.9.jar
├─maven
└─taeget
  *.war
 pom.xml

warの内部は以下の通り
*.war
├─META-INF
└─WEB-INF
  jboss-web.xml
  ├─classes
  └─lib

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?