国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

java - Mavn執行測試時<scope>test</scope>導致錯誤

瀏覽:139日期:2023-11-25 17:43:19

問題描述

學習maven test時,執行mvn test時,會找不到org.junit在pom.xml中已經引入

<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope></dependency> </dependencies>

報錯信息如下java - Mavn執行測試時<scope>test</scope>導致錯誤文件目錄如下java - Mavn執行測試時<scope>test</scope>導致錯誤hello目錄下存在如下文件java - Mavn執行測試時<scope>test</scope>導致錯誤其中GreeterTest為測試

執行mvn compile 或者mvn package也會報錯

當把pom.xml中junit依賴的scope去掉時,編譯和測試都能成功。

<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version></dependency> </dependencies>

造成這個的原因是什么?maven在執行compile時同時編譯*Test的文件嗎,那么為什么mvn test也不能成功?mvn test不是會自動執行*Test的文件嗎?而且scope test確定了測試時會引入junit

問題解答

回答1:

這個問題其實你因為你不熟悉maven文件結構所致.測試類一般是放在src/test/java,而不是放在src/main/java下.maven在編譯的時候,src/main/java下是不引用<scope>test</scope>的jar,而編譯src/test/java下的測試這會引用<scope>test</scope>的jar

標簽: java
相關文章:
主站蜘蛛池模板: 来凤县| 沈丘县| 油尖旺区| 抚州市| 开封市| 格尔木市| 大渡口区| 仁化县| 盐边县| 泸溪县| 永仁县| 西和县| 军事| 沙河市| 伊春市| 孝感市| 隆回县| 新昌县| 安图县| 平罗县| 秭归县| 白山市| 美姑县| 婺源县| 黑水县| 勃利县| 郸城县| 龙陵县| 北辰区| 三台县| 江陵县| 花垣县| 济阳县| 浪卡子县| 西充县| 高安市| 昭苏县| 安岳县| 姚安县| 温州市| 镇赉县|