如何导入从Ant构建文件正确属性和目标? [英] How to import properties and targets from ant build file properly?

查看:95
本文介绍了如何导入从Ant构建文件正确属性和目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使项目具有两个模块。应用程序和服务器。服务器依赖于应用程序。当我编译服务器我想从应用程序到构建包含类文件。但它解析类路径相对于服务器并没有因为进口问题的应用程序。如何使蚂蚁的决心应用位置相对于应用程序和服务器的位置相对到服务器。我din't得到它是如何在蚂蚁文档完成。可否请你以一种更简单的方式解释一下吗? code段,以澄清问题一点。

应用程序的build.xml:

 <项目名称=应用程序>
<属性名=app.build.dir位置=构建/><目标名称=编译>
    <回声消息=编译应用程序到$ {} app.build.dir/>
< /目标与GT;
< /项目>

服务器的build.xml:

 <项目名称=服务器>
<属性名=server.build.dir位置=构建/><包括文件=../应用程序/ build.xml文件/><目标名称=编译取决于=app.compile>
    <回声消息=编译服务器为$ {} server.build.dir使用的类路径:$ {} app.build.dir/>
< /目标与GT;
< /项目>

输出:

 构建文件:D:\\工作\\测试\\蚂蚁TEST2 \\服务器\\ build.xml文件app.compile:
 [回应]编译到D:\\工作\\测试\\蚂蚁TEST2 \\服务器\\建设编译:
 使用类路径\\工作\\测试\\蚂蚁TEST2 \\服务器\\版本:[回应]编译服务器D D:\\工作\\测试\\蚂蚁TEST2 \\服务器\\建设BUILD SUCCESSFUL
总时间:0秒

所需的输出:

 构建文件:D:\\工作\\测试\\蚂蚁TEST2 \\服务器\\ build.xml文件app.compile:
 [回应]编译到D:\\工作\\测试\\蚂蚁TEST2 \\程序\\编译编译:
 使用类路径\\工作\\测试\\蚂蚁TEST2 \\服务器\\版本:[回应]编译服务器D D:\\工作\\测试\\蚂蚁TEST2 \\程序\\编译BUILD SUCCESSFUL
总时间:0秒


解决方案

一个简单的方法是如下:在build.xml的应用程序,而不是

 <属性名=app.build.dir位置=构建/>

使用

 <属性名=app.build.dir位置=../应用程序/编译/>

如果您指定属性按位置(和相对路径),蚂蚁解析相对于当前项目的路径。用这个符号,蚂蚁首先进入上一层目录,然后下到应用程序目录,这是对来自您的项目。

有一个更好的办法是把双方建立在一个单独的属性文件,脚本和包含这个文件来自构建使用的设置。

I want to make project with two modules. App and server. Server depends on app. When I compile server I want to include class files from app into the build. But it resolves classpath relatively to server and not to app because of import issues. How to make ant resolve app locations relatively to app and server locations relatively to server. I din't get how it's done in ant docs. Could you please explain in a more simple way? Code snippet to clarify question little bit.

App build.xml:

<project name="app">
<property name="app.build.dir" location="build"/>

<target name="compile">
    <echo message="Compiling app to ${app.build.dir}"/>
</target>
</project>

Server build.xml:

<project name="server">
<property name="server.build.dir" location="build"/>

<include file="../app/build.xml"/>

<target name="compile" depends="app.compile">
    <echo message="Compiling server to ${server.build.dir} using classpath: ${app.build.dir}"/>
</target>
</project>

Output:

Buildfile: D:\work\test\ant-test2\server\build.xml

app.compile:
 [echo] Compiling to D:\work\test\ant-test2\server\build

compile:
 [echo] Compiling server to D:\work\test\ant-test2\server\build using classpath:  D:\work\test\ant-test2\server\build

BUILD SUCCESSFUL
Total time: 0 seconds

Desired output:

Buildfile: D:\work\test\ant-test2\server\build.xml

app.compile:
 [echo] Compiling to D:\work\test\ant-test2\app\build

compile:
 [echo] Compiling server to D:\work\test\ant-test2\server\build using classpath:  D:\work\test\ant-test2\app\build

BUILD SUCCESSFUL
Total time: 0 seconds

解决方案

A simple approach would be the following: In the build.xml for app instead of

<property name="app.build.dir" location="build"/>

use

<property name="app.build.dir" location="../app/build"/>

If you specify a property by location (and with a relative path), ant resolves the path relative to your current project. With this notation, ant first goes up a directory level and then down to the app dir, which is right from both of your projects.

A better approach would be to put the settings used by both build scripts in a separate property file and include this file from both builds.

这篇关于如何导入从Ant构建文件正确属性和目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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