我有幾個不同的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。 –