问题:maven项目执行单元测试可以正常执行,但是运行mvn install 提示报程序包org.junit不存在
分析:maven项目,单元测试和运行使用不同的classpath,测试使用test-classpath,运行使用classpath
解决方法:在pom.xml中添加如下插件

<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <!-- scope作用域,使用默认的compile,编译、测试、运行都有效的作用域 --> <scope>test</scope> </dependency> </dependencies>