同时采用进口标签更改BASEDIR属性 [英] Change baseDir attribute while using import tag

查看:181
本文介绍了同时采用进口标签更改BASEDIR属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要提供我所面临的问题的背景。

Let me first provide the background of the problem I'm facing.

我有一个目录结构如下图所示。

I have a directory structure as below.

C:\\ myDirectory结果
C:\\ myDirectory \\ PROJECT1结果
C:\\ myDirectory \\脚本

c:\myDirectory
c:\myDirectory\Project1
c:\myDirectory\Scripts

C:\\ myDirectory \\脚本还有就是下载源$ C ​​$ C(从SVN)的脚本,并创建在 C:\\ myDirectory \\ PROJECT1 。目录

Under the c:\myDirectory\Scripts there is a script that download the source code (from svn) and creates the c:\myDirectory\Project1 directory.

我还有一个Ant脚本( C:\\ myDirectory \\ **脚本编译source.xml ),它编译PROJECT1
从下载到的 c。将ant脚本的build.xml:\\ myDirectory \\ PROJECT1

I have another ant scripts ( c:\myDirectory\Scripts**compile-source.xml ) that compiles the Project1 from an ant script build.xml that is downloaded to c:\myDirectory\Project1

片段为C:\\ myDirectory \\ \\脚本编译source.xml

Snippet for c:\myDirectory\Scripts\compile-source.xml

<project name="compile" default="buildAll" basedir=".">
    <property file=".\build.properties">
    </property>
    .......
    <import file="${project.home.path}/${project.name}/build.xml"/>
     <target name="buildAll">
      <antcall target="jar-pack"/>
    </target>
</project>

片段为C:\\ myDirectory \\ PROJECT1 \\ build.xml文件。

Snippet for c:\myDirectory\Project1\build.xml.

<project name="CommonFeatures" default="jar-pack" basedir=".">
        <description>
            A build file for the Common Features project
        </description>
        ....
    </project>

请注意,对于该项目的basedir被设置为。对于上述两种Ant脚本。

Note that the basedir for the project is set as "." for both the above ant scripts.

当我执行该脚本的 C:\\ myDirectory \\脚本\\编译source.xml C:\\ myDirectory \\脚本目录中的目标的罐子-pack present在 C:\\ myDirectory \\ PROJECT1 \\ build.xml文件被执行

When I execute the script c:\myDirectory\Scripts\compile-source.xml from the c:\myDirectory\Scripts directory the target "jar-pack" present in the c:\myDirectory\Project1\build.xml gets executed.

然而,问题是在这的build.xml BASEDIR attribude( BASEDIR = 。)是当前工作目录,在这种情况下,它的 C:\\ myDirectory \\脚本。因此,脚本错误的build.xml出来,因为对build.xml中的BASEDIR预计将 C:\\ myDirectory \\ PROJECT1 。 build.xml脚本会工作,如果BASEDIR =。被设置为C:\\ myDirectory \\ PROJECT1,但遗憾的是build.xml文件来自源$ C ​​$ C被下载,我无法修改

However, the problem is that basedir attribude in build.xml ( basedir="." ) is the current working directory and in this case its c:\myDirectory\Scripts. Hence the script build.xml errors out since the basedir for build.xml is expected to be c:\myDirectory\Project1. The build.xml script would have worked, if basedir="." were set to "c:\myDirectory\Project1", but unfortunately build.xml file comes from the source code that is downloaded and I'm unable to edit.

因此​​,这里是我的问题,是否有可能做任何以下的。

So here's my question, Is it possible to do any of the following.


  1. 重写attribude BASEDIR的值=。在build.xml文件时的 的是在C做?:\\ myDirectory \\脚本\\编译source.xml

  1. Override the value of the attribude basedir="." in build.xml when the is done in c:\myDirectory\Scripts\compile-source.xml ?

是否有可能通过任何其他机制,使脚本c键更改build.xml中的BASEDIR:\\ myDirectory \\ PROJECT1 \\ build.xml文件是根据目录c执行:\\ myDirectory \\ PROJECT1?

Is it possible to change the basedir in build.xml by any other mechanism so that the script c:\myDirectory\Project1\build.xml is executed under directory c:\myDirectory\Project1 ?

要解决此问题的任何其他办法吗?

Any other way to resolve this issue?

从蚂蚁专家来解决这个问题的任何帮助是非常AP preciated。

Any help from Ant experts to overcome this issue is highly appreciated.

推荐答案

有关你的案件的用法 subant 蚂蚁的任务可能更适合,但仍然...

For your case the usage of the subant or ant tasks may be better suited, but nevertheless...

可以(但你应该知道/考虑副作用!)延长蚂蚁与普通的蚂蚁的contrib 任务定义并使用 VAR 任务 这是能够替换属性。确保使用最新版本(&GT; 1.0b3 )。

You can (but you should know/consider the side-effects!) extend ant with the common ant-contrib task definitions and use the var task which is able to override properties. Make sure to use the latest version (> 1.0b3).

<!-- adjust to your path and include it somewhere at the beginning of your project file -->
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="lib/ant-contrib-1.0b3.jar" />

<!-- works e.g. for basedir = /foo/bar to update it to /foo/bar/.. ~ /foo -->
<var name="basedir" value="${basedir}/.." />

更新:但是你要小心,因为这个不改变 (当前工作目录)(所以&LT;属性名=X位置=TMP/&GT; 是相对于 ,而不是 BASEDIR 了;更新:设置 BASEDIR 蚂蚁之外,或通过&LT;项目BASEDIR = 还设置 BASEDIR !)。下面是一些测试目标,证明双方的影响:

update: but one has to be careful, because this does not change . (current working directory) (so <property name="x" location="tmp" /> would be relative to . and not to basedir anymore ; update: setting basedir outside of ant or via <project basedir= also sets . to basedir!). Here is some test target proving the effect on both:

<target name="tst.dummy.basedir-override">
    <!-- example output:
        tst.dummy.basedir-override:
             [echo] basedir before: basedir=D:\tst,  '.'=D:\tst\.
             [echo] updating it via 'var' to '..'
             [echo] basedir now:  basedir=D:\tst/..,  '.'=D:\tst\.
    -->
    <property name="cur" location="." /> <!-- makes the relative path absolute -->
    <echo message="basedir before: basedir=${basedir},  '.'=${cur}" />

    <echo message="updating it via 'var' to '..'" />
    <var name="basedir" value="${basedir}/.." />

    <property name="cur2" location="." /> <!-- makes the relative path absolute -->
    <echo message="basedir now:  basedir=${basedir},  '.'=${cur2}" />
</target>

这篇关于同时采用进口标签更改BASEDIR属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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