0

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?

Will
  • 8,246
  • 16
  • 60
  • 92

2 Answers2

1

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.

Alex Gitelman
  • 24,429
  • 7
  • 52
  • 49
  • Cheers for the quick answer. You were right however it is now giving me a problem with `create MDP.Tar: BUILD FAILED C:\eq-Drop-Copy\eq-mo-drop-copy-converter-shell\build.xml:16: basedir does not exist! ` Yet I know this dir to be true and I can see my build file within it. I'm assuming `basedir="${dcc-mdp.dir}/*"` will mean everything within the dcc-mdp.dir – Will Jun 21 '11 at 15:16
  • you are not correct. basedir must be directory name without `/*`. Same applies to any `dir` argument. – Alex Gitelman Jun 21 '11 at 15:31
  • So how does one specify that it must be all contents of all files? I was assuming the syntax was like that of Unix. Assumptions :( – Will Jun 21 '11 at 15:35
  • if you specify `basedir` that will include all files in it unless controlled by `excludes` and `includes`. I personally prefer to use nested file set for that, though. – Alex Gitelman Jun 21 '11 at 16:00
0

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?

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Yeah it has David explained some of the more elementary functionality. Thank you. For whatever reason thou it still is tar up the target directory and it's contents :S – Will Jun 22 '11 at 08:32
  • Are you still getting an error? Can you post the error message? That'll help me figure out exactly what you're missing. Did you remove the "*" from the `basedir` attributes? This attribute doesn't expand the "*", but will consider it part of the directory name. – David W. Jun 22 '11 at 16:00