Maven打包编译错误工作区间设置编码格式gbk可以utf-8不可以
转自: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代码
代码如下:
package org.xc.binny;
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
public class GBK2UTF8App {
/**
* 将制定目录下的所有Java源文件的编码格式从GBK修改为UTF-8
*/
public static void main(String[] args) throws Exception {
//GBK编码格式源码路径
String srcDirPath = "C:\\Users\\Wolf\\Desktop\\src";
// //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后端\v1.0\parent\ins-service\src\main\java\com\junk
String utf8DirPath = "C:\\Users\\Wolf\\Desktop\\src";
// String srcDirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
// //转为UTF-8编码格式源码路径E:\SVN3\20160918JunKang_Dev\JKDS\05源代码\后端\v1.0\parent\ins-service\src\main\java\com\junk
// String utf8DirPath = "E:\\SVN3\\20160918JunKang_Dev\\JKDS\\05源代码\\后端\\v1.0\\parent\\ins-common\\src\\main\\java\\com\\common";
//
//获取所有java文件
Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[]{"java"}, true);
int count=0;
for (File javaGbkFile : javaGbkFileCol) {
//UTF8格式文件路径
String utf8FilePath = utf8DirPath+javaGbkFile.getAbsolutePath().substring(srcDirPath.length());
//使用GBK读取数据,然后用UTF-8写入数据
// FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
count++;
System.out.println("执行文件次数"+count);
}
}
}
- 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通过编译。
最新文章
- 已安装php 编译安装 gd库拓展模块
- Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique
- jQuery插件编写规范
- response压缩响应
- C语言的数据类型及其对应变量
- 三层架构实例 VB.NET版
- JavaScript表单编程
- 浅析Oracle范式的概念(转载)
- 删除binlog的方法
- CF 369 B. Valera and Contest
- hairline!ios实现边框0.5px
- Oracle core05_事务和一致性
- XML&;DTD&;XML Schema学习
- Linux软件
- RTSP Monitor的总结
- B&#39;day Gift
- lua的学习
- 使用AdvancedInstaller打包web工程设置tomcat端口的方法
- 3D打印技术在医疗上的实际应用与实验室研究
- js中类定义函数时用prototype与不用的区别
热门文章
- 安卓学习之学生签到APP(一)
- 推荐系统入门:作为Rank系统的推荐系统(协同过滤)
- .NET Core &; EntityFrameworkCore
- 【sqli-labs】 less39 GET -Stacked Query Injection -Intiger based (GET型堆叠查询整型注入)
- HDU_5810_数学,概率,方差
- PyCharm 恢复默认设置 | JetBrains IDE 配置文件安装目录
- git_仓库
- java将父类所有的属性COPY到子类中
- 【转载】Java 反射详解
- linux中tomcat启动脚本:关闭、发布、重启、测试是否成功