运行maven时报错如下
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< cn.test:MavenTest >--------------------------
[INFO] Building MavenTest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenTest ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenTest ---
[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 1 source file to E:\java\EclipseTest\MavenTest\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
此环境中不提供编译器。也许您运行的是jre而不是jdk?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.810 s
[INFO] Finished at: 2019-10-19T16:00:15+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project MavenTest: 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
JDK和JRE有如下区别:
相同点:
都可以运行JAVA程序,JDK中包含JRE,JRE本身就是Java运行环境。
不同点:
JDK全称为"JAVA 开发工具包",JRE全称为"JAVA运行环境":
JRE是java runtime environment(java运行环境)的缩写。光有JVM还不能让class文件执行,因为在解释class的时候JVM需要调用解释所需要的类库lib。在JDK的安装目录里你可以找到jre目录,
里面有两个文件夹bin和lib,在这里可以认为bin里的就是jvm,lib中则是jvm工作所需要的类库,而jvm合lib合起来就称为jre。所以,当你写完java程序,也就.java文件时,当其编译成.class文件后,你可以 把这个.class文件和jre发给朋友,这样你的朋友就可以运行你写的程序了(jre中有运行.class的java.exe)。
结局方案
eclipse的Installed JREs 时add jdk,别add jre,然后重新编译运行
[INFO] Scanning for projects…
[INFO]
[INFO] -------------------------< cn.test:MavenTest >--------------------------
[INFO] Building MavenTest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ MavenTest —
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ MavenTest —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ MavenTest —
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenTest —
[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 1 source file to E:\java\EclipseTest\MavenTest\target\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[1,24] 程序包org.junit不存在
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[1,1] 仅从类和接口静态导入
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[3,17] 程序包org.junit不存在
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[10,10] 找不到符号
符号: 类 Test
位置: 类 TestMethend
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[12,17] 找不到符号
符号: 方法 assertEquals(boolean,boolean)
位置: 类 TestMethend
[INFO] 5 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.345 s
[INFO] Finished at: 2019-10-19T16:22:52+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project MavenTest: Compilation failure: Compilation failure:
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[1,24] 程序包org.junit不存在
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[1,1] 仅从类和接口静态导入
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[3,17] 程序包org.junit不存在
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[10,10] 找不到符号
[ERROR] 符号: 类 Test
[ERROR] 位置: 类 TestMethend
[ERROR] /E:/java/EclipseTest/MavenTest/src/test/java/TestMethend.java:[12,17] 找不到符号
[ERROR] 符号: 方法 assertEquals(boolean,boolean)
[ERROR] 位置: 类 TestMethend
[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工程中警告[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[警告]使用时平台编码格式(GBK actually)进行解析的文件资源,也就是说,构建是依赖于平台的!
错误原因:一些源文件的编码格式并不是工具平台的默认的解析格式,二者有冲突,所以报错
解决方法:在maven工程中的父工程POM中加入以下代码“
再次运行时就不会报错。
[INFO] Scanning for projects…
[INFO]
[INFO] -------------------------< cn.test:MavenTest >--------------------------
[INFO] Building MavenTest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ MavenTest —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ MavenTest —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ MavenTest —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenTest —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ MavenTest —
[INFO] Surefire report directory: E:\java\EclipseTest\MavenTest\target\surefire-reports
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom (1.7 kB at 651 B/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (2.3 kB at 5.0 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar (26 kB at 16 kB/s)
T E S T S
Running TestMethend
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.367 s
[INFO] Finished at: 2019-10-19T16:27:54+08:00
[INFO] ------------------------------------------------------------------------
真是不容易搞了一下午卧槽!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)