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

在idea中用tomcat插件运行时打不开浏览器而出现这些代码"C:\Program Files (x86)\Java\jdk1.8.0_121\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\王成远\IdeaProjects\untitled -Djansi.passthrough=true -DarchetypeCatalog=internal -Dmaven.home=C:\Environment\apache-maven-3.6.1 -Dclassworlds.conf=C:\Environment\apache-maven-3.6.1\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.2\lib\idea_rt.jar=51770:C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Environment\apache-maven-3.6.1\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version=2023.1.2 tomcat7:run -P !jdk-1.8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------< org.example:untitled >------------------------ [INFO] Building untitled 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ untitled >>> [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ untitled --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ untitled --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ untitled <<< [INFO] [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ untitled --- [INFO] Skipping non-war project [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.982 s [INFO] Finished at: 2023-06-11T09:39:45+08:00 [INFO] ------------------------------------------------------------------------ Process finished with exit code 0是什么原因
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值