简体   繁体   English

如何从src / main / java中的src / test / resources中读取道具

[英]How to read props from src/test/resources in src/main/java

I've standard maven project... 我有标准的Maven项目...

In src/main/java I've a class called MyResourceLoader.java that load some resource by name my_props.xml . src/main/java我有一个名为MyResourceLoader.java的类,该类通过名称my_props.xml加载一些资源。

In src/test/resource , I've created this my_props.xml . src/test/resource ,我创建了此my_props.xml

Now in src/test/java , I try to invoke the MyResourceLoader.java , but It cannot see my_props.xml .. 现在在src/test/java ,我尝试调用MyResourceLoader.java ,但看不到my_props.xml ..

How to make it visible ?? 如何使其可见?

It should be 它应该是

src/test/resources

Not

src/test/resource

From @sotirios-delimanolis : 来自@ sotirios-delimanolis:

You put your resources in src/ test /resources , and when you run it your aren't testing, you are running it, so maven compiles it and ignores the src/test directory. 您将资源放在src / test / resources中,当您运行它时,您未在进行测试,而您正在运行它,因此maven对其进行编译并忽略src/test目录。

Change it to src/main/resources and see if that fixes the problem, the src/main directotry is what is put into the actual jar. 将其更改为src/main/resources ,看看是否可以解决问题,将src/main maindirectotry放入实际的jar中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM