Maven 3和JUnit 4编译问题:包org.junit不存在 [英] Maven 3 and JUnit 4 compilation problem: package org.junit does not exist

查看:228
本文介绍了Maven 3和JUnit 4编译问题:包org.junit不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Maven构建一个简单的Java项目.在我的pom文件中,我将JUnit 4.8.2声明为唯一的依赖项. Maven仍然坚持使用JUnit版本3.8.1.我该如何解决?

I am trying to build a simple Java project with Maven. In my pom-file I declare JUnit 4.8.2 as the only dependency. Still Maven insists on using JUnit version 3.8.1. How do I fix it?

此问题在编译失败时显现出来:软件包org.junit不存在".这是由于我的源代码中的import语句.在JUnit 4. *中正确的软件包名称是org.junit.*,而在版本3. *中正确的软件包名称是junit.framework.*

The problem manifests itself in a compilation failure: "package org.junit does not exist". This is because of the import statement in my source code. The correct package name in JUnit 4.* is org.junit.* while in version 3.* it is junit.framework.*

我想我已经在 http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html ,但其中的建议似乎是针对Maven专家的.我不知道该怎么办.

I think I have found documentation on the root of the problem on http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html but the advice there seems to be meant for Maven experts. I did not understand what to do.

推荐答案

@Dennis Roberts:您绝对正确:我的测试类位于src/main/java中.同样,在JOM的POM中,"scope"元素的值也是"test",尽管这应该是这样.问题是我在Eclipse中创建测试类时草率,导致在src/test/java中创建的src/main/java中创建了它.运行"mvn eclipse:eclipse"后,这在Eclipse的Project Explorer视图中变得更容易看到,但是您的评论才使我首先看到了它.谢谢.

@Dennis Roberts: You were absolutely right: My test class was located in src/main/java. Also the value of the "scope" element in the POM for JUnit was "test", although that is how it is supposed to be. The problem was that I had been sloppy when creating the test class in Eclipse, resulting in it being created in src/main/java insted of src/test/java. This became easier to see in Eclipse's Project Explorer view after running "mvn eclipse:eclipse", but your comment was what made me see it first. Thanks.

这篇关于Maven 3和JUnit 4编译问题:包org.junit不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆