转义字符在属性过滤中(Maven)

huangapple 未分类评论47阅读模式
英文:

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:

&lt;home.directory&gt;${user.home}/config/templates&lt;/home.directory&gt;

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:

&lt;plugin&gt;
	&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
	&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
	&lt;inherited&gt;false&lt;/inherited&gt;
	&lt;configuration&gt;
		&lt;escapeWindowsPaths&gt;false&lt;/escapeWindowsPaths&gt;
	&lt;/configuration&gt;
&lt;/plugin&gt;

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,还是使用所有的“/”来表示其他情况。

我会尝试更改:

&lt;home.directory&gt;${user.home}/config/templates&lt;/home.directory&gt;

&lt;home.directory&gt;${user.home}\config\templates&lt;/home.directory&gt;

如果你正在使用 Windows。

英文:

Definitely not:
C:\Users\my-laptop/config/templates
When defining a path it's must be consistent, whether all "&quot; for windows of all "/" for the rest.

I'd try to change:

&lt;home.directory&gt;${user.home}/config/templates&lt;/home.directory&gt;

To

&lt;home.directory&gt;${user.home}\config\templates&lt;/home.directory&gt;

If you are using windows.

huangapple
  • 本文由 发表于 2020年4月9日 03:34:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/61108635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定