SlinnShady
SlinnShady

Reputation: 515

ANT war file compile failing when using Tomcat jar

I am trying to use ANT to build a war file. Part of the script compiles a source called HelloClient.java This is a Servlet and I am using the javax.servlet.* jar from Tomcat

1/ When I use javac HelloClient.java at the command line I get the error cannot find symbol public class HelloClient extends HttpServlet

2/ When I use javac -cp C:\Users\jon\apache-tomcat-9.0.39\lib\servlet-api.jar HelloClient.java from the command line it compiles

ant war at the command line gives exactly the same error as 1 above, i.e. error: cannot find symbol public class HelloClient extends HttpServlet

Via IntelliJ I get similar results. When I use the Build Module option IntelliJ compiles the classes and dumps all the docs and web.xml to Production as expected (I have added the Tomcat Lib directory to the Library).

When I try to run my ANT script I get all the same errors as above with what I assume is javac complaining about not having the jars it needs.

I have C:\Users\jon\apache-tomcat-9.0.39\lib in my CLASSPATH

Is there something I should be doing here so that ANT driven compiles can see the jars that are needed?

Upvotes: 1

Views: 101

Answers (1)

SlinnShady
SlinnShady

Reputation: 515

Solved with some ANT classpath work.

   <target name="setup" depends="clean">
    <mkdir dir="${lib-dir}"/>
    <copy file="C:\Users\jon\apache-tomcat-9.0.39\lib\servlet-api.jar" todir="${lib- 
   dir}"/>
   </target>   

  <path id="build.classpath">
    <!-- include all jars in the jar directory and all sub-directories -->
    <fileset dir="${lib-dir}">
        <include name="**/*.jar" />
    </fileset>
   </path>

<target name="compile" depends="setup">
    <mkdir dir="${build-dir}"/>
    <javac includeantruntime="false" srcdir="${src-dir}" destdir="${build-dir}"
    classpathref="build.classpath">
    </javac>
</target>

Upvotes: 1

Related Questions