---
title: "ant发布路径问题"
author: "东流水"
date: "2012-11-26T16:08:23Z"
tags: ["Ant"]
categories: ["开源软件"]
slug: "ant"
draft: false
lastmod: "2012-11-27T18:01:40Z"
id: 1735444
url: "https://992012.iteye.com/blog/1735444"
---

ant中project中有一个basedir属性配置，配置目录用户的，如果没有配置，则为编译xml的当前目录。然后如果有一个target中有java，我们知道每个java运行都有一个运行目录，即user.dir，可用System.getProperty("user.dir")或者，然后无论basedir怎么配置，ant中运行的目录也都是ant配置文件的当前目录。也就是basedir怎么配置都对运行目录是没有作用的，运行目录在使用相对路径的时候就起作用了。basedir配置会对带path，location的属性起作用。例如编译的配置文件build.xml中有以下一个target：

 

```
<target name="check-test">
	   <java classname="deploy.DeployChecker" failonerror="true" maxmemory="16m">
	       <arg value="../deploy/common/deploy-interfacesvr.conf" />
	       <arg value="${basedir}" />
	       <classpath>
	           <pathelement location="deploy/common/deploy.jar" />
	       </classpath>
	   </java>
</target>
```

 

build.xml所在目录是和deploy是同一等级的目录，如果没有配置basedir="../"也就是把ant编译的目录弄到配置文件的父目录，则会出错。配置了，这样就没有问题了。但是其中arg中用相对路径的带一个文件名还是只能在用户的运行路径。顺便说下，其中failonerror配置为true，则当你的java运行不是以0退出，就会编译不成功。即System.exit(0)以外的都会失败。