简体   繁体   中英

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. This is for a project using Maven and the STS IDE.

My .properties file itself is being found and read just fine. 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:

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 has several built in properties that should allow you to insert the correct path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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