简体   繁体   English

如何在属性文件中编写相对路径

[英]How to write relative paths within a properties file

I've looked all over the site but nothing answers this. 我看了整个网站,但没有回答这个问题。 I would like to know how to write a relative path WITHIN a .properties file. 我想知道如何在.properties文件中编写相对路径。 This is for a project using Maven and the STS IDE. 这适用于使用Maven和STS IDE的项目。

My .properties file itself is being found and read just fine. 我的.properties文件本身正在被找到并且读得很好。 But, I am trying to create a relative path within the file itself and it's not working. 但是,我试图在文件本身内创建一个相对路径,但它无法正常工作。

In the .properties file I have this entry: 在.properties文件中,我有这个条目:

XML_PROPERTIES=C:/projects/myProject/project-server/project-webapp/src/main/config/gs/myXmlFile.xml

I want to use a relative path here. 我想在这里使用相对路径。 I've tried: 我试过了:

XML_PROPERTIES=../myXmlFile.xml

and

XML_PROPERTIES=../src/main/config/gs/myXmlFile.xml

and neither of those work. 这些都不起作用。

I've also tried to use expression language to get the project directory like this: 我也尝试使用表达式语言来获取这样的项目目录:

XML_PROPERTIES=${basedir}/src/main/config/gs/myXmlFile.xml

The only things that works is the complete path. 唯一有效的是完整的道路。 Without it, I get errors that look similar to this: 没有它,我会得到类似于此的错误:

Java Global Settings: XML properties file [../src/main/config/gs/agl_gs_NT.xml] not found.

Please let me know if I can provide any more details and I appreciate any responses. 如果我能提供更多详细信息,请通知我,我感谢您的回复。

Use the the maven resources plugin to filter your property value. 使用maven资源插件过滤您的属性值。 Maven has several built in properties that should allow you to insert the correct path. Maven有几个内置属性 ,允许您插入正确的路径。

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

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