我对 Ant 很陌生(我来自 Maven),我发现执行以下操作有很多问题。
我有一个名为CrystalIceGUI的主项目,它使用另一个名为ShellExtBridge的依赖项目。
依赖项目ShellExtBridge有一个自己的build.xml文件,用于编译项目并将其打包到一个 jar 文件中,该 jar 文件放入名为Release的目录中
主项目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 脚本时执行这些操作:
[echo] Into ShellExtBridge build.xml clean target [delete] 删除目录 /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin 编译: [echo] Into ShellExtBridge build.xml 编译目标 [mkdir] Created dir :/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin [javac] /home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/ShellExtBridge/Project/build.xml:37:警告:'includeantruntime'未设置,默认为 build.sysclasspath=last; 为可重复构建设置为 false
它删除此目录/home/andrea/Documenti/XCloud/Implementazione/CrossPlatform/CrystalIceGUI/Project/bin ,而不是与ShellExtBridge项目中的 bin 目录相关的正确目录。
似乎是这样,当它调用ShellExtBridge项目的 ant 文件时,丢失了它的引用并在主项目的文件夹而不是正确项目的文件夹上进行操作。
你有一些解决它的想法吗?