maven 打war包配置文件中的中文注释乱码

本文介绍了解决Maven打包WAR文件时出现的中文乱码问题,通过调整Maven版本和配置解决了部分文件注释乱码的现象。

maven将项目打war包后出现了配置文件中文注释的乱码

乱码现象很奇怪,部分乱码部分没有乱码,也就是比如<!--视图解析器-->这样的注释的话只有器出现了乱码而其他的都是好的。当时自己试了如下情况:

1、Eclipse乱码不可能因为设置了utf-8 ,所以工程中的所有文件都是utf-8编码

2、文件使用的也是utf-8编码

<?xml version="1.0" encoding="UTF-8"?>

所以不是开发环境和文件编码的原因,那只能是maven的原因了

3、对maven编码的配置

<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	</properties>

编码配置后还是不起作用,那是什么原因那。

(1)、在找的时候看到了一篇文章分析的很详细,不小心关了就找不到了,那篇文章的大体意思就是maven有个编码的地方他使用的是null所以会出现这个问题

(2)、也有看到说2.3版本之前配置的编码不起作用

那好我就改版本号

<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-war-plugin</artifactId>
			<version>2.6</version>
			 <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <!--动态定义war包名称,其中的${package.target}就是传过来的值,默认使用开始properties 中定义的package.target的值 -->
                    <warName>sas_bdwallet_${package.target}</warName>
                    <!--就是这里实现了加载不同目录下的配置文件和工程目录结构红框中的路劲是一样的  -->
                    <webResources>
                        <resource>
                            <directory>src/main/resources_${package.target}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <!--使用传递过来的参数 -->
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                    <!--工程下web.xml路劲,不管是什么打包这个都要配置不然会报错  -->
                    <webXml>WebRoot\WEB-INF\web.xml</webXml>
                    <!--js,css,jsp路劲配置,如果不添加则js、css、jsp都不在war包中  -->
                    <warSourceDirectory>WebRoot</warSourceDirectory>
                </configuration>
		</plugin>


看了一下maven的最新版本是3.0.0所以改成了3.0.0虽然配置文件报错但是打包能正常打而且也没了乱码,所以又把3.0.0改成了2.6配置文件不报错了而且乱码问题也没有了,所以最终的问题就是maven的版本号。


4、使用的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.baidu.wallet</groupId>
	<artifactId>sas_bdwallet</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<name>sas_bdwallet</name>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<!--配置默认值-->
		 <package.target>test</package.target>
	</properties>

<!-- 项目所依赖的jar包 -->
	<dependencies>
	<!-- spring springmvc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>4.2.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.2.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>4.2.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.2.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>4.2.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.8.6</version>
		</dependency>
		<!-- mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.3.0</version>
		</dependency>
		<!-- mybatis 链接spring包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.3</version>
		</dependency>
		<!-- mysql 驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.36</version>
		</dependency>
		<!--druid数据库连接池  -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.15</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>1.9.12</version>
		</dependency>
		<!--文件上传  -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<!-- servlet -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>
		<!--jackson-->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.6.1</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.6.1</version>
		</dependency>
		<!--json -->
		<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.4</version>
			<classifier>jdk15</classifier>
		</dependency>

		<!--log -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.2</version>
		</dependency>
		<!-- jsp c标签引入 -->
		<dependency>
			<groupId>org.apache.taglibs</groupId>
			<artifactId>taglibs-standard-spec</artifactId>
			<version>1.2.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.taglibs</groupId>
			<artifactId>taglibs-standard-impl</artifactId>
			<version>1.2.1</version>
		</dependency>

		<!--AES MD5加密编码 -->
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.4</version>
		</dependency>
		<!-- httpclient -->
		 <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
          <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.0.1</version>
        </dependency>
		
		<!--测试 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	
	<!--profile配置 -->
	<profiles>
        <profile>
            <id>test</id>
            <properties>
                <package.target>test</package.target>
            </properties>
        </profile>
        <profile>
            <id>online</id>
            <properties>
                <package.target>online</package.target>
            </properties>
        </profile>
    </profiles>
    
	<build>
	<plugins>
	    <!--编译插件配置-->
	    <plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.7</source>
				<target>1.7</target>
			</configuration>
		</plugin>
		<!--打war包插件配置-->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-war-plugin</artifactId>
			<version>2.6</version>
			 <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <!--动态定义war包名称,其中的${package.target}就是传过来的值,默认使用开始properties 中定义的package.target的值 -->
                    <warName>sas_bdwallet_${package.target}</warName>
                    <!--就是这里实现了加载不同目录下的配置文件和工程目录结构红框中的路劲是一样的  -->
                    <webResources>
                        <resource>
                            <directory>src/main/resources_${package.target}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <!--使用传递过来的参数 -->
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                    <!--工程下web.xml路劲,不管是什么打包这个都要配置不然会报错  -->
                    <webXml>WebRoot\WEB-INF\web.xml</webXml>
                    <!--js,css,jsp路劲配置,如果不添加则js、css、jsp都不在war包中  -->
                    <warSourceDirectory>WebRoot</warSourceDirectory>
                </configuration>
		</plugin>
	</plugins>
</build>
</project>



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值