【问题记录】Eclipse打包Maven项目报错:MojoFailureException

JDK版本:1.7.0_80
Maven版本:3.6.0
Eclipse版本:Eclipse Oxygen

问题描述

使用Maven install命令打包时,出现如下编码错误:

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ shizhan12_2 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 17 source files to E:\workspace\shizhan12_2\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
......
[ERROR] /E:/workspace/shizhan12_2/src/main/java/cn/itcast/kafka/simple/KafkaProducerSimple.java:[66,37] 编码GBK的不可映射字符
......
[ERROR] /E:/workspace/shizhan12_2/src/main/java/cn/itcast/kafka/simple/KafkaConsumerSimple.java:[58,58] -source 1.5 中不支持 diamond 运算符
  (请使用 -source 7 或更高版本以启用 diamond 运算符)
[INFO] 103 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.823 s
[INFO] Finished at: 2019-03-01T23:28:22+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project shizhan12_2: Compilation failure: Compilation failure: 
......
[ERROR] /E:/workspace/shizhan12_2/src/main/java/cn/itcast/order/OrderInfo.java:[13,15] 编码GBK的不可映射字符
......
[ERROR] /E:/workspace/shizhan12_2/src/main/java/cn/itcast/kafka2storm/ParserOrderMqBolt.java:[66,47] -source 1.5 中不支持 diamond 运算符
[ERROR]   (请使用 -source 7 或更高版本以启用 diamond 运算符)
[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

问题分析与解决方法

maven-compiler-plugin插件在编译源码时默认使用source 1.5,应该将source设置为1.7以上的版本,因此在pom.xml中加入如下几行:

<project ...>
  其他有关项目的描述信息
  <dependencies>
    项目的第三方依赖信息
  dependencies>
  
  <build>
  	<plugins>
  		项目的其他插件信息
		<plugin>
			<groupId>org.apache.maven.pluginsgroupId>
			<artifactId>maven-compiler-pluginartifactId>
			<version>3.1version>
			<configuration>
			    <source>1.7source>
			    <target>1.7target>
			configuration>
		plugin>
   	plugins>
  build>
project>

你可能感兴趣的:(JAVA)