ant java task with space issue

岁酱吖の 提交于 2019-12-25 05:14:00

问题


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.

P.S 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.


回答1:


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 f.e. 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.



来源:https://stackoverflow.com/questions/6747814/ant-java-task-with-space-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!