v2ex_com
校友
校友
  • UID186
  • 粉丝1
  • 关注7
  • 发帖数47
  • 社区居民
  • 忠实会员
阅读:2172回复:0

老司机转学java(基础篇) 第15讲 mvn compile 报错

楼主#
更多 发布于:2019-05-04 09:13
由于我用的是JDK1.8 在控制台 运行 mvn compile时报错


F:\pro\myjava>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< groupId:myjava >---------------------------
[INFO] Building myjava 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myjava ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ myjava ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 11 source files to F:\pro\myjava\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /F:/pro/myjava/src/main/java/MyIndex.java:[17,44] 程序包com.sun.activation.registries不存在
[ERROR] /F:/pro/myjava/src/main/java/MyIndex.java:[17,1] 仅从类和接口静态导入
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.516 s
[INFO] Finished at: 2019-05-04T08:49:05+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myjava: Compilation failure: Compilation failure:
[ERROR] /F:/pro/myjava/src/main/java/MyIndex.java:[17,44] 程序包com.sun.activation.registries不存在
[ERROR] /F:/pro/myjava/src/main/java/MyIndex.java:[17,1] 仅从类和接口静态导入
[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

在IDEA的 pom.xml 文件中的plugins 节点里加入如下修改后的配置


        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>

                    <compilerArguments>
                        <!-- 是否输出所有的编译信息(包括类的加载等)-->
                        <!--<verbose />-->
                        <!-- 解决maven命令编译报错,因为rt.jar 和jce.jar在jre的lib下面,不在jdk的lib下面,
                        导致maven找不到(java7以后会出现这个问题),将这2个jar包拷贝到jdk的lib下面估计也好使-->
                        <bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
          </plugin>



再在控制台中运行 mvn compile 可以正常编译

参考文章:
https://www.jianshu.com/p/5ce832ede830
游客

返回顶部