我对Ant非常陌生(我来自Maven),我发现有许多问题需要执行以下操作。
我有一个名为CrystalIceGUI的主项目,它使用另一个名为的依赖项目
依赖项目ShellExtBridge有一个自己的build.xml文件,该文件编译该项目并将其打包到一个jar文件中,该jar文件被放入名为Release的direcotry中。
主项目CrystalIceGUI有它的build.xml ant文件,该文件包含一个名为init的目标,该目标试图执行ShellExtBridge依赖项目的build.xml文件来构建该项目,然后在另一个目标中使用jar。
问题是,如果我执行ShellExtBridge的build.xml ant脚本,它运行良好,jar文件被正确地创建到它的Release目录中(因此我认为这个ant脚本是可以的),但是如果我从主项目的build.xml调用它,它会给我一系列错误。
这是ShellExtBridge依赖项的build.xml:
<?xml version="1.0"?>
<project default="default">
<!-- ============================================ -->
<!-- Load build properties -->
<!-- ============================================ -->
<property name="project.buildfile" value="build.num" />
<property file="${project.buildfile}" />
<property file="info.properties" />
<!-- ============================================ -->
<!-- The default target -->
<!-- ============================================ -->
<target name="default" depends="jar" />
<!-- Elimina le cartelle contenenti le classi compilate ed i jar -->
<target name="clean">
<echo message="Into ShellExtBridge build.xml clean target"/>
<delete dir="../Release" />
<!-- Elimina directory del jar finale -->
<delete dir="bin" />
<!-- Elimina directory delle classi compilate -->
</target>
<!-- Contiene i task di COMPILAZIONE:
1) Crea la directory "bin/" nel progetto
2) Compila tutte le classi dentro la cartella "src" del progetto e mette i risultanti .class
dentro "bin"
-->
<target name="compile" depends="clean">
<echo message="Into ShellExtBridge build.xml compile target"/>
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" />
</target>
<target name="jar" description="Packs classes of shellextbridge" depends="compile">
<echo message="Into ShellExtBridge build.xml jar target"/>
<jar destfile="../Release/shellExtBridge.jar" index="false">
<fileset dir="bin" />
<manifest>
<attribute name="Created-By" value="${info.software.author}" />
<attribute name="Main-Class" value="com.techub.crystalice.rmi.Main" />
</manifest>
</jar>
</target>
</project>这是主项目CrystalIceGUI的build.xml文件的init目标。
<target name="init">
<ant antfile="${basedir}../../../ShellExtBridge/Project/build.xml" />
</target>如果要执行这个ant脚本的init目标,就会得到以下错误:
Buildfile: /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/build.xml
init:
clean:
[echo] Into ShellExtBridge build.xml clean target
[delete] Deleting directory /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin
compile:
[echo] Into ShellExtBridge build.xml compile target
[mkdir] Created dir: /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin
[javac] /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/ShellExtBridge/Project/build.xml:37: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 117 source files to /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin
[javac] /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/src/com/techub/crystalice/utils/QuickLocale.java:8: package org.apache.log4j does not exist
[javac] import org.apache.log4j.Logger;
[javac] ^
[javac] /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/src/com/techub/crystalice/fuse/AtmosFuseWrapper.java:8: package org.apache.log4j does not exist
[javac] import org.apache.log4j.Logger;
[javac] ^
[javac] /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/src/com/techub/crystalice/fuse/AtmosFuseWrapper.java:11: package com.techub.crystalice.jaxb.settings does not exist
[javac] import com.techub.crystalice.jaxb.settings.DriveType;
[javac]
...............................................................................
...............................................................................
ETCETCETC MANY OTHERS SIMILAR ERRORS
...............................................................................
...............................................................................
BUILD FAILED
/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/build.xml:70: The following error occurred while executing this line:
/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/ShellExtBridge/Project/build.xml:37: Compile failed; see the compiler error output for details.如您所见,调用依赖项ShellExtBridge项目的build.xml ant脚本是因为显示了该ant脚本的回显消息。
但是有一件事很奇怪,因为当ShellExtBridge的build.xml脚本被称为执行这些操作时:
删除/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin编译目录:回送到ShellExtBridge build.xml编译目标mkdir创建的dir: /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin javac /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/ShellExtBridge/Project/build.xml:37:警告:“/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/binincludeantruntime”未设置,默认为build.sysclasspath=last;对于可重复构建设置为false
它删除这个目录/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin,而删除与ShellExtBridge项目中的bin目录相关的正确目录。
似乎是这样的,当它调用ShellExtBridge项目的ant文件时,它丢失了它的引用,并在主项目的文件夹上执行操作,而不是对正确的项目执行操作。
你对解决这个问题有什么想法吗?
发布于 2013-10-14 19:42:52
我认为修起来很简单。任务将使用当前目录作为工作目录,除非您指定了dir属性(此外,如果要运行的目标文件名为build.xml,则可以省略antfile属性)。
所以,我建议的init目标是:
<target name="init">
<ant dir="${basedir}../../../ShellExtBridge/Project" />
</target>下面是关于dir属性的官方文档:
dir:要用作新Ant项目的basedir的目录(除非useNativeBasedir设置为true)。默认为当前项目的basedir,除非inheritall设置为false,在这种情况下,它没有默认值。这将覆盖被调用项目的basedir设置。还用作解析antfile和output属性值的目录(如果有的话)。
发布于 2014-08-13 19:17:33
我无法让dir或useNativeBasedir选项单独工作(使用Ant1.9.3)。我必须提供inheritall="false"并为sub构建指定dir选项以使用正确的basedir:
<target name="stage" depends="init">
<ant antfile="../otherproject/build.xml" inheritall="false" dir="../otherproject">
</target>https://stackoverflow.com/questions/19365001
复制相似问题