Maven の pom.xml、war対応版のサンプルを残しておきます。かなりてんこ盛りになってしまいました。。。
動作確認環境
- JDK11
- Eclipse IDE 2020-03(4.15.0)
- Apache Maven 3.6.3
- Jenkins ver. 2.222.3
- checkstyle 8.1.7 (maven-checkstyle-plugin 3.1.1)
- SpotBugs 4 (spotbugs-maven-plugin 4.0.0)
- JUnit 5 (junit-jupiter-api, junit-platform-launcher)
- assertj 3.15.0
- mockito 3.1.0
- JaCoCo 0.8.5
ビルドコマンド
デプロイ先によってwarの内容を変えられる仕組みにしています。
ローカル環境向け
$mvn clean package
検証環境向け
$mvn -P staging clean package
本番環境向け
$mvn -P production clean package
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>4.0.0</modelVersion>
<groupId>com.itbibo.example.web</groupId>
<artifactId>WebCalcu</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WebCalcu Project</name>
<url>http://itbibo.php.xdomain.jp</url>
<properties>
<wtp.version>none</wtp.version>
<env.JAVA_HOME_11>C:\Java\jdk-11.0.7</env.JAVA_HOME_11>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<!-- compiler -->
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<maven.compiler.verbose>true</maven.compiler.verbose>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<junit.jupiter.version>5.7.0-M1</junit.jupiter.version>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
<junit.platform.version>1.7.0-M1</junit.platform.version>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<assertj.version>3.15.0</assertj.version>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<mockito.version>3.1.0</mockito.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- JUnit 3 and JUnit 4
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
<build>
<finalName>${buildFinalName}</finalName>
<resources>
<resource>
<filtering>false</filtering>
<directory>${resource.directory}</directory>
<excludes>
<!-- These files should be excluded for environmental configuration -->
<exclude>a.properties</exclude>
<exclude>conf/b.properties</exclude>
</excludes>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<filtering>false</filtering>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
<release>${java.version}</release>
</configuration>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-resources-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jxr-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- https://maven.apache.org/plugins/maven-war-plugin/usage.html -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<archive>
<!-- https://maven.apache.org/plugins/maven-war-plugin/examples/war-manifest-guide.html -->
<!-- http://maven.apache.org/shared/maven-archiver/index.html -->
<manifest>
<addDefaultEntries>true</addDefaultEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<packageName>WebCalculation</packageName>
<useUniqueVersions>true</useUniqueVersions>
</manifest>
<!-- http://maven.apache.org/shared/maven-archiver/examples/manifestEntries.html -->
<manifestEntries>
<mode>${environment}</mode>
<url>${project.url}</url>
</manifestEntries>
<!-- https://maven.apache.org/shared/maven-archiver/examples/manifestSections.html -->
<manifestSections>
<manifestSection>
<name>section1</name>
<manifestEntries>
<param1>value11 value12</param1>
<param2>value21 value22</param2>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
<warSourceExcludes>**/*exclude.js,**/b.properties</warSourceExcludes>
<!-- web.xml 設定 -->
<webXml>configs/${environment}/web.xml</webXml>
<!-- context.xml 設定 -->
<containerConfigXML>configs/${environment}/context.xml</containerConfigXML>
<webResources>
<resource>
<directory>WebContent</directory>
<targetPath>/</targetPath>
<includes>
<include>**/*.jsp</include>
</includes>
</resource>
<resource>
<directory>configs/${environment}</directory>
<targetPath>/</targetPath>
<includes>
<include>index.js</include>
</includes>
</resource>
<resource>
<directory>configs/${environment}</directory>
<targetPath>WEB-INF/classes/</targetPath>
<includes>
<include>a.properties</include>
</includes>
</resource>
<resource>
<directory>configs/${environment}</directory>
<targetPath>WEB-INF/classes/conf/</targetPath>
<includes>
<include>b.properties</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Dfile.encoding=UTF-8</argLine>
<argLine>${jacoco.agent.argLine}</argLine>
<!-- <skipTests>true</skipTests> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-failsafe-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>tree</id>
<phase>package</phase>
<goals>
<goal>tree</goal>
</goals>
<configuration>
<outputFile>dependency.txt</outputFile>
<outputType>text</outputType>
</configuration>
</execution>
</executions>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-checkstyle-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.17</version>
</dependency>
</dependencies>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<violationSeverity>error</violationSeverity>
<consoleOutput>true</consoleOutput>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-report-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-eclipse-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<downloadSources>true</downloadSources>
<wtpversion>${wtp.version}</wtpversion>
</configuration>
</plugin>
<!-- https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-maven-plugin -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.0.0</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<failOnError>true</failOnError>
<trace>true</trace>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>target/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>jacoco-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment>local</environment>
<resource.directory>src/main/resources</resource.directory>
<buildFinalName>${project.artifactId}-dev</buildFinalName>
</properties>
</profile>
<profile>
<id>staging</id>
<properties>
<environment>staging</environment>
<resource.directory>${basedir}/configs/staging/resources</resource.directory>
<buildFinalName>${project.artifactId}-staging</buildFinalName>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<environment>production</environment>
<resource.directory>${basedir}/configs/production/resources</resource.directory>
<buildFinalName>${project.artifactId}</buildFinalName>
</properties>
</profile>
</profiles>
<reporting>
<plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jxr-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-project-info-reports-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
<reportSets>
<reportSet>
<reports>
<report>ci-management</report>
<report>dependencies</report>
<report>dependency-convergence</report>
<report>dependency-info</report>
<report>dependency-management</report>
<report>distribution-management</report>
<report>help</report>
<report>index</report>
<report>issue-management</report>
<report>licenses</report>
<report>mailing-lists</report>
<report>modules</report>
<report>plugin-management</report>
<report>plugins</report>
<report>scm</report>
<report>summary</report>
<report>team</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-report-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<showSuccess>false</showSuccess>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>config/your_project_checkstyle.xml</configLocation>
</configuration>
</plugin>
<!-- https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-maven-plugin -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.0.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Eclipseプロジェクト構成
![](http://itbibo.starfree.jp/wp-content/uploads/2020/05/WebCalcuPom01.png)
Calcu
│ pom.xml
│
├─configs
│ ├─local
│ │ context.xml
│ │ web.xml
│ │
│ ├─production
│ │ │ context.xml
│ │ │ web.xml
│ │ │
│ │ └─resources
│ │ │ a.properties
│ │ │ index.js
│ │ │
│ │ └─conf
│ │ b.properties
│ │ c.properties
│ │
│ └─staging
│ │ context.xml
│ │ web.xml
│ │
│ └─resources
│ │ a.properties
│ │ index.js
│ │
│ └─conf
│ b.properties
│ c.properties
│
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─itbibo
│ │ │ └─example
│ │ │ └─web
│ │ │ ├─calc
│ │ │ │ CalcExcAdd.java
│ │ │ │ CalcExcMul.java
│ │ │ │ CalcInit.java
│ │ │ │
│ │ │ └─hello
│ │ │ HelloWorld.java
│ │ │
│ │ ├─resources
│ │ │ │ a.properties
│ │ │ │ index.js
│ │ │ │
│ │ │ └─conf
│ │ │ b.properties
│ │ │ c.properties
│ │ │
│ │ └─webapp
│ └─test
│ ├─java
│ └─resources
│
└─WebContent
│ index.jsp
│
├─META-INF
│ MANIFEST.MF
│
└─WEB-INF
│ web.xml
│
└─jsp
└─calc
input.jsp
result.jsp