我有一个涉及黄瓜和maven的项目,由Intellij IDEA负责。
我需要使用相对文件路径。现在我正在Mac OS上工作,但是该项目也将在Windows上使用。
这是我的RunnerTest.Java类
public class RunnerTest {
public static void main(String[] args) throws Throwable {
System.setProperty("TagConfigFile", "../../config/application.properties");
//...
String sConfigFile = System.getProperty("TagConfigFile", "null");
try (InputStream streamFromResources = Props.class.getClassLoader().getResourceAsStream(sConfigFile)) {
/* work wiht streamFromResources */
} catch (IOException | NullPointerException ee) {
throw new PropsRuntimeException("Failed to access properties file", ee);
}
}
}
这是我的项目结构的图像(为清楚起见,添加了突出显示):
我试图使用这种方式。但这没有帮助
1. "../../config/application.properties"
2. "src/resources/config/application.properties"
3. "../../resources/config/application.properties"
我不假装是正确的,但是它起作用了:
resources
,src -> main
然后将文件夹移到了config
那里。我在其中创建了文件夹resources
,src -> test
并将所有其他文件夹移到了那里。结果是这样的结构:src
|----main
| |
| |----java
| |----resources
| | |----config
| | | |----application.properties
|
|----test
| |----resources
| | |----features
| | |----pipes
| | |----testdata
| | |----webdrivers
System.setProperty("TagConfigFile", "../../config/application.properties");
我System.setProperty("TagConfigFile", "./config/application.properties");
在RunnerTest.java
课堂上写如果有人提供更精美的工作解决方案,我将非常高兴
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句