问题
I have a little ant script which should create 3 tar files.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." >
<property name="dcc-shell.dir" value="${basedir}"/>
<property name="dcc-mdp.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir" value="${dcc-mdp.dir}/src/main/*"/>
<property name="dcc-srv.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir" value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir" value="${dcc-trans.dir}/src/main/*"/>
<target name="create MDP Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
basedir="${dcc-mdp.dir}/**"
excludes="${dcc-mdp.dir}/target/*"
/>
</target>
<target name="create Trans Tar">
<tar destfile="${dcc-shell.dir}/trans.tar"
basedir="${dcc-trans.dir}/**"
excludes="${dcc-trans.dir}/target/*"
/>
</target>
<target name="create SRV Tar">
<tar destfile="${dcc-shell.dir}/srv.tar"
basedir="${dcc-srv.dir}/**"
excludes="${dcc-srv.dir}/target/*"
/>
</target>
</project>
The script runs fine:
Buildfile: C:\eq-Drop-Copy\eq-mo-drop-copy-converter-shell\build.xml
BUILD SUCCESSFUL
Total time: 94 milliseconds
However no tar files are created within the project. Somewhat of a mystery to myself
EDIT I have been getting the following error!
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
I have changed the xml to the absoulet paths:
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
However still the same error how can the basedir not exist the build file is contained within it. The basedir within the MDP target is pointing to an absoulet path and tar all the files within that. why would this be giving an error?
回答1:
I corrected several issues:
basedir
attribute shouldn't have "*" in it. It'll automatically do the whole tree.- Targets can't contain spaces
You probably didn't specify targets. Therefore, I simply added a
default
target "create_all_tars", and used<antcall>
to call the needed targets.<project basedir="." default="create_all_tars" > <property name="dcc-shell.dir" value="${basedir}"/> <property name="dcc-mdp.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/> <property name="mdp-code.dir" value="${dcc-mdp.dir}/src/main/*"/> <property name="dcc-srv.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/> <property name="srv-code.dir" value="${dcc-srv.dir}/src/main/*"/> <property name="dcc-trans.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/> <property name="trans-code.dir" value="${dcc-trans.dir}/src/main/*"/> <target name="create_all_tars"> <antcall target="create_MDP_Tar"/> <antcall target="create_Trans_Tar"/> <antcall target="create_SRV_tar"/> </target> <target name="create_MDP_Tar"> <tar destfile="${dcc-shell.dir}/mdp.tar" basedir="${dcc-mdp.dir}" excludes="${dcc-mdp.dir}/target/**"/> </target> <target name="create_Trans_Tar"> <tar destfile="${dcc-shell.dir}/trans.tar" basedir="${dcc-trans.dir}" excludes="${dcc-trans.dir}/target/**"/> </target> <target name="create_SRV_Tar"> <tar destfile="${dcc-shell.dir}/srv.tar" basedir="${dcc-srv.dir}" excludes="${dcc-srv.dir}/target/**"/> </target>
Does this help?
回答2:
Most likely you called it without giving a target. Your printout does not show any tar targets executed. Try calling it with target name as argument to ant. Then you will also find out that using spaces in target names may not be such a good idea.
来源:https://stackoverflow.com/questions/6427162/ant-not-creating-tar-files