英文:
Escape Characters in Property Filtering (Maven)
问题
我正在尝试使用Maven属性过滤来配置文件夹路径,以便将路径保存在属性文件中。因此,我已将Maven属性设置为:
<home.directory>${user.home}/config/templates</home.directory>
在属性文件中,我已将其设置为:
working.directory=${home.directory}
最终的属性文件如下:
working.directory=C:\\Users\\my-laptop/config/templates
但是,当我尝试在Java中使用此属性文件时,我得到的路径是:
C:\\\\Users\\\\my-laptop/config/templates
不用说,这个路径是无法正常工作的。因此,我尝试使用 maven-resources-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<escapeWindowsPaths>false</escapeWindowsPaths>
</configuration>
</plugin>
这个插件使情况变得更糟。我得到的路径是:
C\:Usersmy-laptop/config/templates
请问有什么办法可以解决这个问题吗?例如:
C:\Users\my-laptop/config/templates
或者 C:/Users/my-laptop/config/templates
英文:
I am trying to configure the folder path using Maven property filtering to save the path in a properties file. So I have the maven property set as:
<home.directory>${user.home}/config/templates</home.directory>
In the properties file I have set it up as:
working.directory=${home.directory}
The final property file turns out like:
working.directory=C:\\Users\\my-laptop/config/templates
But when I try to do something with this property file in JAVA, I get the path as:
C:\\\\Users\\\\my-laptop/config/templates
Needless to say this path doesn't work. So I tried using maven-resources-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<escapeWindowsPaths>false</escapeWindowsPaths>
</configuration>
</plugin>
This one messes it up even further. I get the path as:
C\:Usersmy-laptop/config/templates
Can you please tell me a way to set this right? Like:
C:\Users\my-laptop/config/templates
or C:/Users/my-laptop/config/templates
答案1
得分: 0
绝对不是:
C:\Users\my-laptop/config/templates
在定义路径时必须保持一致,无论是使用所有的“\”来表示 Windows,还是使用所有的“/”来表示其他情况。
我会尝试更改:
<home.directory>${user.home}/config/templates</home.directory>
为
<home.directory>${user.home}\config\templates</home.directory>
如果你正在使用 Windows。
英文:
Definitely not:
C:\Users\my-laptop/config/templates
When defining a path it's must be consistent, whether all "" for windows of all "/" for the rest.
I'd try to change:
<home.directory>${user.home}/config/templates</home.directory>
To
<home.directory>${user.home}\config\templates</home.directory>
If you are using windows.
专注分享java语言的经验与见解,让所有开发者获益!
评论