开发者

Not able to copy jar to an absolute path

I am trying to copy Demo.jar file (generated by an ant task) on my desktop(or any directory specified by it's absolute path on my XP machine).

I am specifying absolute path in a properties file and reading it on the fly. The problem is I am not able to read this absolute path properly, where I want my Demo.jar to be copied.

Absolute path given in properties file is :-

"C:\Documents and Settings\Administrator\Desktop\google\my java"

and script is echoing :-

[echo] C:Documents and SettingsAdministratorDesktopgooglemy java

Below is my edited version of build.xml and antParams.properties:-

build.xml

<project default="copy">

    <property file="antParams.properties" prefix="antPar开发者_如何转开发ams"/>

    <target name="jar" >
        <jar destfile="${antParams.jarName}"
             basedir="${antParams.binDir}"
            includes="**/*.class"

             />
    </target>

    <target name="copy" depends="jar">
            <echo>${antParams.jarDestination}</echo>
        <!-- what goes here --> 
    </target>

</project>

antParams.properties

jarName=Demo.jar
binDir=bin
jarDestination=C:\Documents and Settings\Administrator\Desktop\

Thanx in advance.... :-)


The problem is in the reading of the properties file, and has nothing to do with Ant or its flexibility in recognizing file separators.

As explained in the java.util.Properties documentation, escape sequences start with \. If you want a literal backslash, you need to escape it: \\.

… a non-zero even number of 2n contiguous backslashes before a line terminator (or elsewhere) encodes n backslashes after escape processing.


Use double backslashes (c:\\Doc ...), or better yet, use forward slash (c:/Doc ...). Ant knows how to use forward slash in a cross-platform way, it converts it correctly to backslashes on windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜