1.问题: 为什么Maven Update Project JDK变回1.5

解释:官方文档

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

译:编译器插件用来编译项目的源文件.从3.0版本开始, 用来编译Java源文件的默认编译器是javax.tools.JavaCompiler (如果你是用的是java 1.6) . 如果你想强制性的让插件使用javac,你必须配置插件选项 forceJavacCompilerUse. 同时需要注意的是目前source选项和target 选项的默认设置都是1.5, 与运行Maven时的JDK版本无关. 如果你想要改变这些默认设置, 可以参考 Setting the -source and -target of the Java Compiler中的描述来设置 source 和target 选项.

解决办法:1.全局解决方式(针对所有项目),2.局部解决方式(只针对当前项目)

解决1:设置全局的jdk,在setting.xml文件中的profiles元素添加profile配置

    <profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>

Jdk版本信息根据自己的情况修改。

如果找不到setting.xml文件,请查看:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension

解决2:在项目的pom,xml文件中添加如下build元素

    <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

问题解决

2.问题:eclipse 中 右击项目 执行 Run As--> Maven install

输出信息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project eboot: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[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其实是有一个默认的仓库.m2仓库和默认的settings.xml配置文件,我们在这个默认的settings.xml文件中也添加了一个JAVA8_HOME的变量后,编译就通过了,这就说明,maven编译的时候找的不是我在idea中配置的我自定义的settings.xml,而是先找的它默认的那个。因为里面没有,所以之前找不到JAVA8_HOME,导致编译失败、

解决办法:在setting.xml文件中的profiles元素添加profile配置,

    <profile>
<id>custom-compiler</id>
<properties>
<JAVA8_HOME>D:\Program Files\Java\jdk1.8.0_101</JAVA8_HOME>
</properties>
</profile>

需要激活上面的配置,在profiles配置外添加activeProfiles元素

  <activeProfiles>
<activeProfile>custom-compiler</activeProfile>
</activeProfiles>

JAVA_HOME路径根据自己的情况配置

问题解决

参考文档:http://blog.csdn.net/kqygww/article/details/12922135

http://blog.csdn.net/u011734144/article/details/51894942

关于eclipse创建Maven项目创建的问题的更多相关文章

  1. 分模块创建maven项目(一)

    maven是一个项目构建和管理的工具. 我们可以通过maven仓库可以实现管理构建(主要是JAR还包括:WAR,ZIP,POM等等). 我们可以通过maven插件可以实现编译源代.产生Javadoc文 ...

  2. m2eclipse简单使用,创建Maven项目 ,运行mvn命令(转)

    前面介绍了如何安装m2eclipse,现在,我们使用m2ecilpse导入Hello World项目. 选择菜单项File,然后选择Import,我们会看到一个Import对话框,在该对话框中选择Ge ...

  3. (八)Eclipse创建Maven项目运行mvn命令

    1.Eclipse创建Maven项目 使用Eclipse创建一个Maven项目非常的简单,选择菜单项File>New>Other(也可以在项目结构空白处右击鼠标键),在弹出的对话框中选择M ...

  4. 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)

    [项目管理和构建]十分钟教程,eclipse配置maven + 创建maven项目(三) 上篇博文中我们介绍了maven下载.安装和配置(二),这篇博文我们配置一下eclipse,将它和maven结合 ...

  5. Maven安装和配置,eclipse创建Maven项目

    提示:使用Maven需要先安装jdk. 下载安装Maven 一.下载最新版的Maven,下载地址:http://maven.apache.org/download.cgi 二.将Maven下载到E:\ ...

  6. 用eclipse创建maven项目

    Maven是基于项目对象模型(POM),也可以进行模块化开发.并且是个强大的管理工具.本经验用eclipse来创建maven项目 步骤: 1.下载并正确安装eclipse 2.在eclipse上成功安 ...

  7. eclipse配置maven + 创建maven项目

        登录|注册     努力+坚持,而且还很年轻   目录(?)[+] 在现实的企业中,以低成本.高效率.高质量的完成项目,不仅仅需要技术大牛,企业更加需要管理大牛,管理者只懂技术是远远不够的.当 ...

  8. eclipse 创建maven 项目 动态web工程报错

    Eclipse 创建maven 项目 动态web工程 注:Eclipse版本为(Version: Mars.1 Release (4.5.1))maven版本为(apache-maven-3.3.9) ...

  9. eclipse配置maven + 创建maven项目(三)

    上篇博文中我们介绍了maven下载.安装和配置(二),这篇博文我们配置一下eclipse,将它和maven结合,并我们创建一个maven的项目. 准备工作 在eclipse配置maven之前需要我们做 ...

随机推荐

  1. UVA - 11732 "strcmp()" Anyone?左兄弟右儿子trie

    input n 2<=n<=4000 s1 s2 ... sn 1<=len(si)<=1000 output 输出用strcmp()两两比较si,sj(i!=j)要比较的次数 ...

  2. 50条规则提高PHP开发提高效率技巧

    0.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作 参数的“函数”(译注:PHP手 ...

  3. SQLite错误总结 error code 19: constraint failed

    SQLite错误总结 1. android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed错误原 ...

  4. 隐式intent启动电子邮件,不需要非电子邮件应用程序。

    Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType("text/plain"); intent.put ...

  5. JS取非行间样式

    <title>无标题文档</title> <style> #div1{width:200px;height:200px; background:red;} < ...

  6. jQuery 数据滚动(上下)

    setInterval(function() { jq('.sjbg02 li:first').animate({ 'height': '0', 'opacity': '0' }, 'slow', f ...

  7. android sql Cursor

    Cursor 是每行的集合. 使用 moveToFirst() 定位第一行. 你必须知道每一列的名称.你必须知道每一列的数据类型.Cursor 是一个随机的数据源. 所有的数据都是通过下标取得. Cu ...

  8. 判断浏览器增加标签 encodeURIComponent

    var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; var lx; (s = ua.match(/msie ([\d.]+ ...

  9. Chapter 1 First Sight——9

    One of the best things about Charlie is he doesn't hover. 一件最好的事是查理兹他不在附近. He left me alone to unpac ...

  10. .Net 中的反射(查看基本类型信息)

    反射概述 和Type类 1.反射的作用 简单来说,反射提供这样几个能力:1.查看和遍历类型(及其成员)的基本信息和程序集元数据(metadata):2.迟绑定(Late-Binding)方法和属性.3 ...