我有几个不同的NetBeans项目链接在一起。我有一个MainProject
,链接SubProject
作为编译时库。未在NetBeans build.xml文件中设置Ant变量的子项目
我试图修改Ant build.xml
脚本MainProject
来设置一个新的Ant变量。我可以在MainProject
中正确设置并查看此变量,但SubProject
的Ant build.xml
脚本没有看到此变量。
我build.xml
脚本MainProject
<?xml version="1.0" encoding="UTF-8"?>
<project name="MainProject" default="default" basedir=".">
<description>Builds, tests, and runs the project MainProject.</description>
<import file="nbproject/build-impl.xml"/>
<target name="-pre-init">
<echo>MainProject Pre Init</echo>
<echo>${ant.version}</echo>
<property name="test.test.test" value="isset" />
<echo>test.test.test=${test.test.test}</echo>
</target>
</project>
我build.xml
脚本SubProject
<?xml version="1.0" encoding="UTF-8"?>
<project name="SubProject" default="default" basedir=".">
<description>Builds, tests, and runs the project SubProject.</description>
<import file="nbproject/build-impl.xml"/>
<target name="-pre-init">
<echo>SubProject Pre Init</echo>
<echo>test.test.test=${test.test.test}</echo>
</target>
</project>
现在,当我在MainProject
我得到以下输出运行clean and build
:
ant -f C:\\sandbox\\MainProject -Dnb.internal.action.name=rebuild clean jar
MainProject Pre Init
Apache Ant(TM) version 1.9.7 compiled on April 9 2016
test.test.test=isset
init:
deps-clean:
Updating property file: C:\sandbox\MainProject\build\built-clean.properties
SubProject Pre Init
test.test.test=${test.test.test}
SubProject.init:
SubProject.deps-clean:
Updating property file: C:\sandbox\MainProject\build\built-clean.properties
Deleting directory C:\sandbox\SubProject\build
SubProject.clean:
Deleting directory C:\sandbox\MainProject\build
clean:
MainProject Pre Init
Apache Ant(TM) version 1.9.7 compiled on April 9 2016
test.test.test=isset
init:
deps-jar:
Created dir: C:\sandbox\MainProject\build
Updating property file: C:\sandbox\MainProject\build\built-jar.properties
SubProject Pre Init
test.test.test=${test.test.test}
SubProject.init:
SubProject.deps-jar:
Created dir: C:\sandbox\SubProject\build
Updating property file: C:\sandbox\MainProject\build\built-jar.properties
Created dir: C:\sandbox\SubProject\build\classes
Created dir: C:\sandbox\SubProject\build\empty
Created dir: C:\sandbox\SubProject\build\generated-sources\ap-source-output
Compiling 1 source file to C:\sandbox\SubProject\build\classes
SubProject.compile:
Created dir: C:\sandbox\SubProject\dist
Copying 1 file to C:\sandbox\SubProject\build
Nothing to copy.
Building jar: C:\sandbox\SubProject\dist\SubProject.jar
To run this application from the command line without Ant, try:
java -jar "C:\sandbox\SubProject\dist\SubProject.jar"
SubProject.jar:
Created dir: C:\sandbox\MainProject\build\classes
Created dir: C:\sandbox\MainProject\build\empty
Created dir: C:\sandbox\MainProject\build\generated-sources\ap-source-output
Compiling 1 source file to C:\sandbox\MainProject\build\classes
compile:
Created dir: C:\sandbox\MainProject\dist
Copying 1 file to C:\sandbox\MainProject\build
Copy libraries to C:\sandbox\MainProject\dist\lib.
Building jar: C:\sandbox\MainProject\dist\MainProject.jar
To run this application from the command line without Ant, try:
java -jar "C:\sandbox\MainProject\dist\MainProject.jar"
jar:
BUILD SUCCESSFUL (total time: 4 seconds)
如何获得SubProject
以查看${test.test.test}
变量的状态,因为它由MainProject
设置?
编辑 - 我正在使用NetBeans自动生成ant
为我的项目构建脚本。 Netbeans创建一个build-impl.xml
和一个build.xml
。当您调用ant
进程时,它会调用build-impl.xml
中的目标。然后build-impl.xml
将在build.xml
中调用我的自定义代码。例如,在NetBeans IDE中运行clean and build
将调用build-impl.xml
中的相应目标,并且build-impl.xml
将依次调用我在build.xml
中的自定义代码。我可以发布build-impl.xml
脚本,但它们只是由Netbeans IDE生成的标准脚本。
我在Main和sub中看到'-pre-init'目标。任何原因? – Rao
如何调用子项目的目标?可以发布可重复的构建脚本?另外检查你是否可以使用subant - https://ant.apache.org/manual/Tasks/subant.html – Rao
Rao,谢谢你的回复。要回答您的问题,我正在使用NetBeans IDE。 NetBeans创建一个'build-impl.xml'和一个'build.xml'。我用我的附加代码发布了我的'build.xml'。我可以发布'build-impl.xml',但它们是由IDE自动生成的。当你运行一个构建时,它会调用'build-impl.xml'中的目标,这会在'build.xml'中引入你的自定义代码。 '-pre-init'目标是由'build-impl.xml'提供的,它将在运行'build-impl.xml'中的'init'目标之前运行您的自定义代码。我没有在'build-impl.xml'文件中看到subant。 –