Getting Started with Maven | Maven Quick Start | Encoding and Compiler Settings
Edit the pom.xml created in the previous “Creating and Running a Project” article, and configure the encoding and compiler version.
Supplement
When the previous mvn package command was run, warnings like the following appeared in a Windows environment.
...
[WARNING] Using platform encoding (MS932 actually) to copy filtered resources, i.e. build is platform dependent!
...
[WARNING] File encoding has not been set, using platform encoding MS932, i.e. build is platform dependent!
...
After applying the settings in this article, these warnings disappear.
1. pom.xml Before Changes
If you created the previous program, the following pom.xml should have been generated.
my-app/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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devkuma.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2. pom.xml After Changes
Edit pom.xml and save the following contents.
my-app/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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devkuma.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Main Changes
Add properties, set the encoding to UTF-8, and set the compiler version to 1.8.
The details are as follows.
project.build.sourceEncoding: Encoding for source and property files.project.reporting.outputEncoding: Encoding for report output resources.maven.compiler.source:javac-sourcesetting.maven.compiler.target:javac-targetsetting.
Other Changes
- Added blank lines.
- Changed to a newer JUnit version, 4.12.
- Removed the
nameandurltags because they are not needed here.
3. Run the package Command
Confirm that the warnings no longer appear with the following command.
$ mvn clean package
Use clean to remove the previous build output first.