(异常-Junit) 程序包org.junit不存在

前言

Junit打包.

程序包org.junit不存在
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[7,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[8,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[9,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[9,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[12,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[32,10] 找不到符号
  符号:   类 BeforeClass
  位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[40,10] 找不到符号
  符号:   类 Test
  位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[70,10] 找不到符号
  符号:   类 AfterClass
  位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[31,10] 找不到符号
  符号:   类 BeforeClass
  位置: 类 com.yanxml.bigdata.java.spark.demos.exam.ExameDataTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[218,10] 找不到符号
  符号:   类 Test
  位置: 类 com.yanxml.bigdata.java.spark.demos.exam.ExameDataTrainDemo
[INFO] 10 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.409 s
[INFO] Finished at: 2020-07-05T17:54:18+08:00
[INFO] Final Memory: 39M/289M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spark: Compilation failure: Compilation failure:
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[7,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[8,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[9,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[9,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[12,17] 程序包org.junit不存在
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[32,10] 找不到符号
[ERROR] 符号:   类 BeforeClass
[ERROR] 位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[40,10] 找不到符号
[ERROR] 符号:   类 Test
[ERROR] 位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/clickhistory/ClickHistoryTrainDemo.java:[70,10] 找不到符号
[ERROR] 符号:   类 AfterClass
[ERROR] 位置: 类 com.yanxml.bigdata.java.spark.demos.clickhistory.ClickHistoryTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[31,10] 找不到符号
[ERROR] 符号:   类 BeforeClass
[ERROR] 位置: 类 com.yanxml.bigdata.java.spark.demos.exam.ExameDataTrainDemo
[ERROR] /Users/sean/Documents/Gitrep/bigdata/spark/src/main/java/com/yanxml/bigdata/java/spark/demos/exam/ExameDataTrainDemo.java:[218,10] 找不到符号
[ERROR] 符号:   类 Test
[ERROR] 位置: 类 com.yanxml.bigdata.java.spark.demos.exam.ExameDataTrainDemo
[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内引用.
		<!-- https://mvnrepository.com/artifact/junit/junit -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope> 
		</dependency>

其本来是test部分进行编译的. 写在src/java/main部分, 编译时没法获取引用.

  • 解决措施
<!-- https://mvnrepository.com/artifact/junit/junit -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope> 
		</dependency>

去除scope标签.


Others

后来看到一篇博客. 突然发现, <scope>即是maven的声明周期有关. 其中, <scope>test</scope>, 即在maven的test周期内生效.


Reference

[1]. maven 程序包org.junit不存在

[2]. Maven打包 错误: 程序包org.junit不存在

©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页