maven-war-plugin的encoding

因为编程环境一直是linux,我一直采用的是UTF-8万能编码。

最近svn co了一个GB18030的项目。mvn war:war打包部署发现了很多配置文件中文乱码,导致启动时解析出错。

我一直以为是maven-resource-plugin的问题,

 

Java代码   收藏代码
  1. /** 
  2.      * <b>If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified()</b> 
  3.      * @param from the file to copy 
  4.      * @param to the destination file 
  5.      * @param encoding the file output encoding (only if wrappers is not empty) 
  6.      * @param wrappers array of {@link FilterWrapper} 
  7.      * @throws IOException if an IO error occurs during copying or filtering 
  8.      */  
  9.     public static void copyFile( File from, File to, String encoding, FilterWrapper[] wrappers )  
  10.         throws IOException  
  11.     {  
  12.         copyFile( from, to, encoding, wrappers, false );  
  13.     }  

  反复查看了这个plugin的源代码之后发现它确实是采用pom里的encoding过滤文件。但是出war包里就是乱码,没天理啊。

 

很久之后我才想到可能是maven-war-plugin的问题。google一搜在官网发现了一个todo 

org.apache.maven.plugin.war.packaging.AbstractWarPackagingTaskLine

add encoding support (null mean platform encoding)

 

看了下源代码

 

Java代码   收藏代码
  1.     if ( context.getWebappStructure().registerFile( sourceId, targetFilename ) )  
  2.     {  
  3.         final File targetFile = new File( context.getWebappDirectory(), targetFilename );  
  4.         try  
  5.         {  
  6.             // fix for MWAR-36, ensures that the parent dir are created first  
  7.             targetFile.getParentFile().mkdirs();  
  8.             // TODO: add encoding support (null mean platform encoding)  
  9.             context.getMavenFileFilter().copyFile( file, targetFile, true, context.getFilterWrappers(), null );  
  10.         }  
  11.         catch ( MavenFilteringException e )  
  12.         {  
  13.             throw new MojoExecutionException( e.getMessage(), e );  
  14.         }  
  15.         // Add the file to the protected list  
  16.         context.getLog().debug( " + " + targetFilename + " has been copied (filtered)." );  
  17.         return true;  
  18.     }  
  19.     else  
  20.     {  
  21.         context.getLog().debug(  
  22.             " - " + targetFilename + " wasn't copied because it has already been packaged (filtered)." );  
  23.         return false;  
  24.     }  
  25. }  
 

  context.getMavenFileFilter().copyFile( file, targetFile, true, context.getFilterWrappers(), null );

encoding是null啊,默认用环境的encoding,坑爹啊


http://www.iteye.com/problems/89646

http://jilen.iteye.com/blog/1145515

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值