Maven打包扔到linux服务器后配置文件乱码的问题

把web工程的war包发布到Linux服务器上总是报错exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence,具体如下:

[2015-09-02 09:32:52 uq_www] INFO [pool-2-thread-3] XmlBeanDefinitionReader.loadBeanDefinitions(315) | Loading XML bean definitions from class path resource [applicationContext.xml]
[2015-09-02 09:32:53 uq_www] INFO [pool-2-thread-3] XmlBeanDefinitionReader.loadBeanDefinitions(315) | Loading XML bean definitions from class path resource [applicationContext/db-context.xml]
[2015-09-02 09:32:53 uq_www] ERROR [pool-2-thread-3] ContextLoader.initWebApplicationContext(331) | Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [applicationContext/db-context.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext/db-context.xml]; nested exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence

对比db-context.xml文件的编码方式是UTF-8,文件首行是 <?xml version="1.0" encoding="UTF-8"?> 也不错。然后使用maven build,命令是clean package。

生成的war包里,使用notepad++打开db-context.xml总是有部分中文注释乱码,但在eclipse里显示是没有乱码的。想必就是此问题了。于是暂时把问题定位

在maven的插件上,根据一些博客的提示陆续把pom.xml做成这样的配置:

plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warSourceDirectory>WebRoot</warSourceDirectory>
        <webResources>
            <resource>
                <directory>${package.environment}</directory>
                <targetPath>WEB-INF/classes</targetPath>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
    <version>2.2</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>
<plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-resources-plugin</artifactId>
       <version>2.6</version>
       <configuration>
         <encoding>UTF-8</encoding>
       </configuration>
  </plugin>

还有这样:

< properties> <project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding> </properties>
同样不可以。

那么接下来莫非是我eclipse环境有问题,于是这样:

- 修改Eclipse中文本文件的默认编码:windows -> Preference -> general -> Workspace -> Text file encoding设置为UTF-8
- 修改JAVA源文件的默认编码:windows->Preferences->general->Content Types->右侧Context Types树,点开Text,选择Java Source File,在下面的Default encoding输入框中输入UTF-8,点Updat


这样就可以了。后来我又把pom.xml配置改为原来的,即不配置maven-resources-plugin的编码方式,也删除<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>此项,然而生成的war包仍是正常的。这样看来其实是eclipse的环境问题了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值