有空间问题的 ant java 任务 [英] ant java task with space issue

查看:22
本文介绍了有空间问题的 ant java 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过 ant 脚本执行 jar 文件.像这样

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 具有 jar 文件的完整路径,并且其中包含一些空间.

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

当我在 Linux 上执行它时,没有问题.但是当我在 Windows 上做同样的事情时,我得到了错误.java任务找不到jar!我尝试了所有不同的变体,例如用引号 (") 包装文件路径,用 " 替换空格,尝试用反斜杠转义等.不工作!

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!

有人遇到过这个问题吗?只是想知道这是 Ant 的限制还是我错过了什么.

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

P.S 抱歉没有提供我收到的完整错误信息.我现在不在我的 Windows PC 上.作为一种解决方法,我决定将 jar 复制到 C:\ 并使用它.

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.

推荐答案

处理属性内空间问题的推荐方法是将它们放入额外的 '',在大多数情况下应该可以工作,甚至更好地使用没有空格的路径

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.

编辑
你说得对,它不会工作,因为只有 jar 属性的相对路径
事实上,我想到了类似的东西:

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>

并且它也出人意料地适用于路径中的空格作为 f.e.在上面的片段中

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}'"

但它没有.

这篇关于有空间问题的 ant java 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆