简体   繁体   中英

ant java task with space issue

I was trying to execute a jar file via ant script. Like this

<java jar="${jar.file}" fork="true" failonerror="true">
   <arg line="${jar.args}"/>
</java>

jar.file has full path to the jar file and contains some space in it.

When I executed that on Linux, there was no problem. But when I do the same on Windows I got error. java task couldn't locate the jar, I've tried all different variations like wrapping the file path with quote ("), replaced space with ", tried escaping with backslash. etc. Non works!

Did anyone come across this issue? Just wondering if this is Ant's limitation or I missed something.

PS Sorry for not providing the full error message I got. I'm away of my Windows PC right now. As a workaround, I decided to copy the jar to C:\ and used that instead.

The recommended way to handle space problems within properties is to put them in extra '', which should work in most cases, even better to use a path without spaces

<java jar="'${jar.file}'" fork="true" failonerror="true">
   <arg line="${jar.args}"/>
</java>

should work, as already mentioned in my comment.

edit
you're right it won't work because of the relative path with only jar attribute
in fact i thought of something like:

<project>
 <property name="jar.file" value="foobar.jar"/>
 <property name="jar.dir" value="/home/rosebud/temp/path with blanks"/>

 <java
   dir="${jar.dir}"
   jar="${jar.dir}/${jar.file}"
   fork="true"
   failonerror="true"
   >
   <arg value="..." />
 </java>
</project>

and it works unexpectedly also with spaces in path as fe in the snippet above

thought the standard way to handle space problems would fit in as in other cases:

"'${property with blanks}'"

but it doesn't.

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