java - Mavn執(zhí)行測試時<scope>test</scope>導(dǎo)致錯誤
問題描述
學(xué)習(xí)maven test時,執(zhí)行mvn test時,會找不到org.junit在pom.xml中已經(jīng)引入
<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>
報錯信息如下文件目錄如下
hello目錄下存在如下文件
其中GreeterTest為測試
執(zhí)行mvn compile 或者mvn package也會報錯
當(dāng)把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在執(zhí)行compile時同時編譯*Test的文件嗎,那么為什么mvn test也不能成功?mvn test不是會自動執(zhí)行*Test的文件嗎?而且scope test確定了測試時會引入junit
問題解答
回答1:這個問題其實你因為你不熟悉maven文件結(jié)構(gòu)所致.測試類一般是放在src/test/java,而不是放在src/main/java下.maven在編譯的時候,src/main/java下是不引用<scope>test</scope>的jar,而編譯src/test/java下的測試這會引用<scope>test</scope>的jar
相關(guān)文章:
1. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. javascript - JS設(shè)置Video視頻對象的currentTime時出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...3. javascript - 圖片能在網(wǎng)站顯示,但控制臺仍舊報錯403 (Forbidden)4. MySQL客戶端吃掉了SQL注解?5. 網(wǎng)頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應(yīng)該怎么解決6. 數(shù)據(jù)庫 - MySQL 單表500W+數(shù)據(jù),查詢超時,如何優(yōu)化呢?7. objective-c - iOS怎么實現(xiàn)像QQ或者微信的實時推送8. php自學(xué)從哪里開始?9. 求大神幫我看看是哪里寫錯了 感謝細心解答10. phpstady在win10上運行
