Resource file encoding problem in MAVEN project __ code

Source: Internet
Author: User

In Maven engineering, resource files are typically placed under the/src/test/resources path, and resource file descriptions are configured in Pom.xml:

<resources>
	<resource>
		<directory>src/main/resources</directory>
		< filtering>true</filtering>
	</resource>
</resources>
This specifies that the files under the path are automatically copied to the classes directory when they are packaged.

However, this configuration uses the

<filtering>true</filtering>
Indicates that the file under this path needs to filter the ER expression in the Copy project and replace the expression with the configured value.

However, the problem appears in this step, the replacement process does not specify the encoding of the file, resulting in the replacement of the file may have garbled problems.

The solution is as follows:

To add a configuration to the Pom.xml file

<plugin>
	<artifactId>maven-resources-plugin</artifactId>
	<version>2.5</ version>
	<configuration>
		<encoding>UTF-8</encoding>
	</configuration>
</plugin>
This means that the file encoding used to filter files is specified by the plugin, avoiding the garbled behavior.

Of course, direct use

<filtering>false</filtering>
There is no such problem.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.