zoukankan      html  css  js  c++  java
  • 关于eclipse创建Maven项目创建的问题

    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 FilesJavajdk1.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

    Java JavaScript ECMAScript 小严
  • 相关阅读:
    使用vue-cookies操作cookie
    JavaScript如何友好的操作的cookie
    揭秘——TCP的三次握手和四次挥手
    python学习之【第八篇】:Python中的函数基础
    python学习之【第七篇】:Python中的集合及其所具有的方法
    python学习之【第六篇】:Python中的字典及其所具有的方法
    php判断是不是手机端访问
    php判断浏览器还是微信打开
    php无限极分类方法
    javascript/jquery获取url地址栏参数的方法
  • 原文地址:https://www.cnblogs.com/JNUX/p/6287146.html
Copyright © 2011-2022 走看看