Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassPath in Ant for Javac task

Tags:

javac

ant

I have following ant file to build. But unfortunately

<project default="build.deploy.start" basedir=".">

    <property name="target.dir" value="C:\tom\webapp\"/>
    <property name="basesrc.dir" value="c:\SimpleChat\"/>   
    <property name="classes.target" value="${basesrc.dir}\WebContent\WEB-INF\classes"/>
    <property name="src.dir" value="${basesrc.dir}\src"/>
    <property name="classpath" value="${basesrc.dir}\WebContent\WEB-INF\classes"/>

    <!-- Classpath for the project -->  
    <path id="master-classpath">
      <fileset dir="${classpath}">
        <include name="*.jar"/>
      </fileset>
    </path>

    <!-- init method which will ensure that all directories exists before we start building/deploying-->
    <target name="init">
        <mkdir dir="${target.dir}\js"/>
        <mkdir dir="${target.dir}\images"/>
        <mkdir dir="${target.dir}\pages"/>
        <mkdir dir="${target.dir}\WEB-INF\lib"/>
        <mkdir dir="${target.dir}\WEB-INF\classes"/>
    </target>

    <!--To build an application so that files can be deloyed-->
    <target name="build" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.target}">
            <classpath refid="master-classpath"/>
        </javac>
    </target>
</project>

I have respective jar files in the LIB directory specified in path element. and yet it gives compilation error that package does not exists as it cannot see my JAR file.

Can you please point out the mistake that I am doing to include that jar correctly?

like image 260
Priyank Avatar asked Aug 11 '09 13:08

Priyank


People also ask

What is classpath in ant?

Ant - Classpaththe location attribute refer to a single file or directory relative to the project's base directory (or an absolute filename) the path attribute accepts colon- or semicolon-separated lists of locations.

What is javac task?

Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file. It only compiles if either . class is not present or . class is older than Java file.

What is includeAntRuntime in ant?

includeAntRuntime. Whether to include the Ant run-time libraries in the classpath. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run. No; defaults to yes , unless build.sysclasspath property is set.


1 Answers

Hard to tell. I can't see any obvious mistakes.

All the examples here: http://ant.apache.org/manual/Types/fileset.html use:

<include name="**/*.jar"/>

instead of just "*.jar" as you have, but what you have looks like it should be ok so long as the .jar files are directly inside \WebContent\WEB-INF\classes.

like image 63
Andy Balaam Avatar answered Nov 11 '22 10:11

Andy Balaam