maven-war-plugin的乱码问题(3字节的UTF-8序列的字节3⽆
效)报错
最近⽤到maven-war-plugin这个插件来进⾏打包,但是打完包启动tomcat会遇到这个报错:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\apache-tomcat-7.0.63_eclipse\webapp
at org.springframework.l.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:410)
at org.springframework.l.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)error parse new
at org.springframework.l.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.t.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.t.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at t.freshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at t.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:604)
at t.fresh(AbstractApplicationContext.java:509)
at org.figureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.t.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.tInitialized(ContextLoaderListener.java:107)
at org.StandardContext.listenerStart(StandardContext.java:5017)
at org.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.ContainerBase.addChild(ContainerBase.java:877)
at org.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
at urrent.Executors$RunnableAdapter.call(Executors.java:471)
at urrent.FutureTask.run(FutureTask.java:262)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: s.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 ⽆效。
at s.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:687)
at s.internal.impl.ad(UTF8Reader.java:435)
at s.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1753)
at s.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1252)
at s.internal.impl.XMLScanner.scanComment(XMLScanner.java:778)
at s.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(XMLDocumentFragmentScannerImpl.java:1038)
at s.internal.impl.(XMLDocumentFragmentScannerImpl.java:297 at s.internal.(XMLDocumentScannerImpl.java:606)
at s.internal.(XMLNSDocumentScannerImpl.java:117)
at s.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at s.internal.parsers.XML11Configuration.parse(XML11Configuration.java:
848)
at s.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at s.internal.parsers.XMLParser.parse(XMLParser.java:141)
at s.internal.parsers.DOMParser.parse(DOMParser.java:243)
at s.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at org.springframework.l.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
at org.springframework.l.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
at org.springframework.l.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 26 more
就是报
3 字节的 UTF-8 序列的字节 3 ⽆效
错误应该是XML⽂件编码问题。到报错xml发现⾥⾯有中⽂注释,的确乱码了。
我确认了⼀下我XML⽂件的编码:
<?xml version="1.0" encoding="UTF-8"?>
UTF-8的编码,idea默认编码也是UTF-8,再确认了⼀下我pom中的encoding:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
也配置了UTF-8,但是没起作⽤啊。
想到可能是maven-war-plugin的问题
google⼀下,查了⼀下源码:
发下了⼀个巨⼤⽆⽐的坑
if ( WebappStructure().registerFile( sourceId, targetFilename ) )
{
final File targetFile = new File( WebappDirectory(), targetFilename );
try
{
// fix for MWAR-36, ensures that the parent dir are created first
// TODO: add encoding support (null mean platform encoding)
}
catch ( MavenFilteringException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
// Add the file to the protected list
return true;
}
else
{
" - " + targetFilename + " wasn't copied because it has already been packaged (filtered)." );
return false;
}
}
看到没有!!
encoding是null,也就是取操作系统默认的编码 我⽤的win
⽽win环境默认是GBK,所以会乱码了。。。⽽且win不像linux可以随意更改系统默认编码所以⽤这个插件打包,有中⽂就坑了。。。。。
⽬前的解决办法是去掉注释中的中⽂。
如有更好的办法,请交流。⼗分感谢
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论