简体   繁体   中英

Best way to add classpath to build.xml

I have this target in build.xml to compile a class:

<target name="-do-compile" depends="init, deps-jar, -pre-pre-compile, -pre-compile, -copy-manifest, -copy-persistence-xml, -copy-webdir, library-inclusion-in-archive,library-inclusion-in-manifest" if="have.sources">
    <webproject2:javac destdir="${build.classes.dir.real}"/>
        <copy todir="${build.classes.dir.real}">
            <fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
        </copy>
</target>

There is also this:

<target name="-init-macrodef-javac">
        <macrodef name="javac" uri="http://www.netbeans.org/ns/web-project/2">
            <attribute name="srcdir" default="${src.dir}"/>
            <attribute name="destdir" default="${build.classes.dir.real}"/>
            <attribute name="classpath" default="${javac.classpath}:${j2ee.platform.classpath}"/>
            <attribute name="debug" default="${javac.debug}"/>
            <element name="customize" optional="true"/>
            <sequential>
                <javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
                    <classpath>
                        <path path="@{classpath}"/>
                    </classpath>
                    <compilerarg line="${javac.compilerargs}"/>
                    <customize/>
                </javac>
            </sequential>
        </macrodef>
    </target>

During compilation, I got an error 'javax.servlet does not exist'. So I have to add classpath to servlet-api.jar, which is in /opt/java/common/ . What is the best way to do it in my build.xml, what should be modified?

As the question may look silly, one may downvote instead of answering. But this certainly won't help, which is what they are here for.

Add below line to your classpath element

<pathelement location="/opt/java/common/servlet-api.jar"/>

ie in your build xml file

<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}"   
                        source="${javac.source}" target="${javac.target}" includeantruntime="false">
      <classpath>
          <path path="@{classpath}"/>
          <pathelement location="/opt/java/common/servlet-api.jar"/>
      </classpath>
      <compilerarg line="${javac.compilerargs}"/>
      <customize/>
</javac>

Please see http://ant.apache.org/manual/using.html Path-like Structures Section

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM