maven junit.framework不存在问题解决

来源:互联网 发布:矩阵a与b相似,则a与b 编辑:程序博客网 时间:2024/05/24 05:01

问题

在使用maven进行一个工程的编译,已加入junit包的依赖,编译的时候却总是报“junit.framework不存在”错误。

pom.xml中junit包加入如下:

    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.12</version>        <scope>test</scope>    </dependency>

解决

试了N多方法,包括加入junit-dep包,依然解决不了问题,后来在加junit-dep包的时候发现,原来多了一个scope属性,将scope属性去掉后恢复正常。

    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.12</version>    </dependency>

原来依赖加入scope属性后,就会被约束在该生命周期内,在compile阶段不引入test阶段的依赖,也就是说编译阶段该依赖无效。

如果修改scope属性,则也可以正常运行:

    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.12</version>        <scope>compile</scope>    </dependency>


0 0