简体   繁体   English

java.home属性写入属性文件时会添加额外的斜杠?

[英]java.home property adds extra slashes when it it written to a property file?

As per my understanding, java.home is a ANT built-in property. 据我了解, java.home是ANT的内置属性。 In our scenerio, we write the value of java.home to a another property file in the same project . 在场景中,我们将java.home的值写入同一项目中的另一个属性文件。 Hovewer, we observed that when we write the value of java.home to the aforesaid property file, the value is written with additional slashes(eg: 'd:/jdk1.6.0_12' value is written to aforesaid property file as 'd\\:\\\\jdk1.6.0_12\\\\jre' ) and these additional slashes are causing issues in our system. Hovewer,我们观察到,当我们将java.home的值写入上述属性文件时,该值将以其他斜杠写入(例如: 'd:/jdk1.6.0_12'值将以'd \\的形式写入上述属性文件:\\\\ jdk1.6.0_12 \\\\ jre' ),这些额外的斜杠会导致系统出现问题。

So, I need your suggestion/help/input to know 1) if there is a way to write java.home to another property file without additional slashes OR 2)if there is a way to write script in ANT build file such that when java.home property will be read from aforesaid property file which containss additional slashes, the script will chop-off unwanted/additional slashes and will return the exact path to java.home . 因此,我需要您的建议/帮助/输入才能知道1)是否有一种方法可以将java.home写入另一个属性文件而没有其他斜杠,或者2)如果有一种方法可以在ANT构建文件中编写脚本,例如当java .home属性将从包含附加斜杠的上述属性文件中读取,脚本将截去不想要的/附加的斜杠,并将精确路径返回到java.home

In a property-file, the \\ is an escape-character, which is used to escape all characters which have special meanings in the property-file-syntax, like a : here. 在属性文件中, \\是转义字符,用于转义所有在属性文件语法中具有特殊含义的字符,例如:这里。 It should be stripped of when reading the property file. 读取属性文件时,应将其删除。 Isn't it? 是不是

For exporting the value, maybe a simple <echo file="...">${java.home}</echo> instead of the property-file-export would be more useful? 对于导出值,也许简单的<echo file="...">${java.home}</echo>代替property-file-export会更有用吗?

Here is a solution to this problem: 这是解决此问题的方法:

<path id="property.toreplace.path">
    <pathelement path="${property.toreplace}"/>
</path>
<pathconvert targetos="unix" property="formatted.property.toreplace" refid="property.toreplace.path"/>

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

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