![](/img/trans.png)
[英]JUnit tests in Maven multi-module project throw NoClassDefFoundError
[英]Unable to find resource in JUnit test in Maven multi-module project
我正在使用Maven 3.0.3,JUnit 4.8.1和Java 1.6。 我在JUnit测试文件中有这个...
@Before
public void loadTestProps() throws IOException, GeneralSecurityException {
final InputStream in = getClass().getClassLoader().getResourceAsStream("test.properties");
testProps = new Properties();
testProps.load(in);
未获取“ test.properties”(输入流对象为null)。 我的项目结构如下:
父+-pom.xml
+-战争模块
+ ------ pom.xml
+ ------ src / test / java / JUnit文件
+ ------ src / test / resources / test.properties
+ ---耳模
+ ------- pom.xml
我宁愿将“ src / test / resources”目录保留在WAR模块中,因为测试仅与WAR文件有关。 有什么办法可以重写上面的Java以找到我的“ test.properties”,还是必须将文件移出WAR模块?
代替getResourceAsStream(“ test.properties”); 您应该使用getResourceAsStream(“ / test.properties”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.