转自:https://blog.csdn.net/wolf_love666/article/details/52593483

问题:Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以 
错误如下: 
[INFO] ———————————————————————— 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ins-service: Compilation failure 
[ERROR] javac: �Ҳ����ļ�: E:\SVN3\20160918JunKang_Dev\JKDS\05源代�?后端\v1.0\parent\ins-service\src\main\java\com\junk\enums\FileUploadEnum.java 
[ERROR] �÷�: javac 
[ERROR] -help �����г����ܵ�ѡ�� 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command 
[ERROR] mvn -rf :ins-service 
解决办法: 
根据出现的乱码发现应该推测到格式编码问题,所以验证下,改工作区间编码格式为gbk呀呀,竟然好了。再改会utf-8格式呀呀又出错了,很奇怪,推测问题是两种: 
一种是原来的gbk现在utf-8但是很明显问题不对路,但是还是提供一种解决方式将gbk代码改成utf-8代码 
代码如下:

  1. package org.xc.binny;
  2. import java.io.File;
  3. import java.util.Collection;
  4. import org.apache.commons.io.FileUtils;
  5. public class GBK2UTF8App {
  6. /**
  7. * 将制定目录下的所有Java源文件的编码格式从GBK修改为UTF-8
  8. */
  9. public static void main(String[] args) throws Exception {
  10. //GBK编码格式源码路径
  11. String srcDirPath = "C:\\Users\\Wolf\\Desktop\\src";
  12. // //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后端\v1.0\parent\ins-service\src\main\java\com\junk
  13. String utf8DirPath = "C:\\Users\\Wolf\\Desktop\\src";
  14. // String srcDirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
  15. // //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后端\v1.0\parent\ins-service\src\main\java\com\junk
  16. // String utf8DirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
  17. //
  18. //获取所有java文件
  19. Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[]{"java"}, true);
  20. int count=0;
  21. for (File javaGbkFile : javaGbkFileCol) {
  22. //UTF8格式文件路径
  23. String utf8FilePath = utf8DirPath+javaGbkFile.getAbsolutePath().substring(srcDirPath.length());
  24. //使用GBK读取数据,然后用UTF-8写入数据
  25. // FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
  26. FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
  27. count++;
  28. System.out.println("执行文件次数"+count);
  29. }
  30. }
  31. }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

jar包:commons-io-1.4.jar 
第二种是maven编译的问题: 
搜罗pom文件关于编译的问题原来: 
maven中的plugins 和 pluginManagement、dependencies和dependencyManagement。这两个后者都需要放置在父文件里面,前者在子文件里。他们区别是: 
maven会在当前项目中加载plugins声明的插件;

pluginManagement是表示插件声明,即你在项目中的pluginManagement下声明了插件,maven不会加载该插件,pluginManagement声明可以被继承。

pluginManagement的一个使用案例是当有父子项目的时候,父项目中可以利用pluginManagement声明子项目中需要用到的插件, 之后,当某个或者某几个子项目需要加载该插件的时候,就可以在子项目中plugins节点只配置 groupId 和 artifactId就可以完成插 件的引用。 
pluginManagement主要是为了统一管理插件,确保所有子项目使用的插件版本保持一致。 
哈哈问题找到了那么改一下吧: 
将 
<pluginManagement> 
<plugins> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<configuration> 
<source>1.6</source> 
<target>1.6</target> 
<encoding>utf-8</encoding> 
</configuration> 
</plugin> 
...... 
</plugins> 
<pluginManagement> 
改成: 
<build> 
<plugins> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<configuration> 
<source>1.6</source> 
<target>1.6</target> 
<encoding>utf-8</encoding> 
</configuration> 
</plugin> 
...... 
</plugins> 
<build>
 
那么原因到底是什么呢为啥呢gbk可以通过,utf-8不可以呢 
由于系统默认编码是GBK,因此默认可以gbk通过编译。

Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以的更多相关文章

  1. 解决maven打包编译出现File encoding has not been set问题

    maven打包编译时后台一直输出警告信息 [WARNING] File encoding has not been set, using platform encoding GBK, i.e. bui ...

  2. 记一次maven打包编译文件一直不正确

    maven打包发现war包解压后的class文件总是跟原Java不一样 后来发现pom中这么写到 <plugins> <plugin> <artifactId>ma ...

  3. eclipse开发Groovy代码,与java集成,maven打包编译

    今天尝试了一下在eclipse里面写Groovy代码,并且做到和Java代码相互调用,折腾了一下把过程记录下来. 首先需要给eclipse安装一下Groovy的插件,插件地址:https://gith ...

  4. IntelliJ IDEA开发Scala代码,与java集成,maven打包编译

    今天尝试了一下在IntelliJ IDEA里面写Scala代码,并且做到和Java代码相互调用,折腾了一下把过程记录下来. 首先需要给IntelliJ IDEA安装一下Scala的插件,在IDEA的启 ...

  5. Maven打包编译找不到com.sun.crypto.provider.SunJCE类

    Maven配置 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>mav ...

  6. maven打包遇到错误,Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test

    对Pom文件进行配置(亲自尝试,已成功解决) <build> <plugins> <plugin> <groupId>org.apache.maven. ...

  7. Android Retrofit2.1.0设置编码格式GBK

    设置接口如下: public interface IHttpService { /** * 获取userId * @param params * @return */ @FormUrlEncoded ...

  8. Eclipse中三种设置编码格式的方法

    转自:https://blog.csdn.net/rainy_black_dog/article/details/52403735 很早以前听过一位老师说过:咱们中国人不管学习哪种编程语言,总会遇到乱 ...

  9. 解决Maven并行编译中出现打包错误问题的思路

    解决Maven并行编译中出现打包错误问题的思路 并行构建 Maven 3.x 提供了并行编译的能力,通过执行下列命令就可以利用构建服务器的多线程/多核性能提升构建速度: mvn -T 4 clean ...

随机推荐

  1. Verification之PSL之intro

    1 PSL - Property specification language 1.1 Property - Characteristics of the designs/verification e ...

  2. css属性代码大全总结(一)

    一 CSS文字属性: color : #999999; /*文字颜色*/ font-family : 宋体,sans-serif; /*文字字体*/ font-size : 9pt; /*文字大小*/ ...

  3. C++程序设计实验安排

    2016-2017第二学期C++程序设计的实验时间与地点安排如下表,请大家根据时间按时来上机实验.另外,因为原来安排在4.1的实验因为调休补周一的课,因此挪至周五.另外第4次周六的课,考虑有一些同学有 ...

  4. alert弹出框 弹出窗口 ----sweetAlert

    推荐一款好用的alert,下面地址是demo,很直观的看到效果,wap可以使用 http://www.dglives.com/demo/sweetalert-master/example/   < ...

  5. (转)基于MVC4+EasyUI的Web开发框架经验总结(11)--使用Bundles处理简化页面代码

    http://www.cnblogs.com/wuhuacong/p/4073203.html 在Web开发的时候,我们很多时候,需要引用很多CSS文件.JS文件,随着使用更多的插件或者独立样式文件, ...

  6. vue-router同路由地址切换无效解决

    本来还想写的,一搜就有现成的,算了: http://blog.csdn.net/peng_guan/article/details/59702699

  7. react工具库

    采用了react框架后,需要找到一些常用的库,常见的需求比如: 1)react生成二维码 2)react的轮播banner图 随着react的社区的壮大,以上的需求都有专门的库帮我们做这个: 1)re ...

  8. mysql主主同步

    Mysql 主主同步方案 第一台机器主 [root@master ~]# vim /etc/my.cnf [mysqld] server-id=1 log-bin=mysql-binlog log-s ...

  9. 【JavaScript游戏开发】使用HTML5+Canvas+JavaScript 封装的一个超级马里奥游戏(包含源码)

    这个游戏基本上是建立在JavaScript模块化的开发基础上进行封装的,对游戏里面需要使用到的游戏场景进行了封装,分别实现了Game,Sprite,enemy,player, base,Animati ...

  10. java 反射之获取泛型对象的所有字段与对应的值(包括父类的)

    上代码: public static void main(String[] args) throws IntrospectionException { SysUser obj = new SysUse ...