2 Replies Latest reply on Apr 5, 2004 3:30 PM by sendres2

    Servlet won't compile

    sendres2 Newbie

      I have a servlet created in my default package for my project. It's a very simple Hello World servlet I was using just to test my environment setup. I have a build.xml file created to compile the classes and create .jar/.war files. However, the first task (compilation) is failing with the following errors when I run it with ANT:

      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:16: package javax.servlet does not exist
      [javac] import javax.servlet.ServletException;
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:17: package javax.servlet does not exist
      [javac] import javax.servlet.ServletOutputStream;
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:18: package javax.servlet.http does not exist
      [javac] import javax.servlet.http.HttpServlet;
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:19: package javax.servlet.http does not exist
      [javac] import javax.servlet.http.HttpServletRequest;
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:20: package javax.servlet.http does not exist
      [javac] import javax.servlet.http.HttpServletResponse;
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:22: cannot resolve symbol
      [javac] symbol : class HttpServlet
      [javac] location: class HelloWorldServlet
      [javac] public class HelloWorldServlet extends HttpServlet
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:25: cannot resolve symbol
      [javac] symbol : class HttpServletRequest
      [javac] location: class HelloWorldServlet
      [javac] protected void service(HttpServletRequest request, HttpServletResponse response)
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:25: cannot resolve symbol
      [javac] symbol : class HttpServletResponse
      [javac] location: class HelloWorldServlet
      [javac] protected void service(HttpServletRequest request, HttpServletResponse response)
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:26: cannot resolve symbol
      [javac] symbol : class ServletException
      [javac] location: class HelloWorldServlet
      [javac] throws ServletException, IOException
      [javac] ^
      [javac] C:\J2SE\Java_Components\Eclipse\eclipse\workspace\MetaDataRepository2\Java\HelloWorldServlet.java:28: cannot resolve symbol
      [javac] symbol : class ServletOutputStream
      [javac] location: class HelloWorldServlet
      [javac] ServletOutputStream out = response.getOutputStream();
      [javac]

      I have checked, and the javax.servlet package is definitely in the /lib folder for JBOSS. Additionally, I tried adding it manually to the build path, but this has not helped either. An excerpt of my build.xml file:

      <!-- Global properties for this build -->







      <!-- Task 1: Compile the classes -->










      which shows the task I'm running which is failing. Any ideas why it won't compile the servlet? Is there something else I need to install to make this work? ANY information or suggestions would be appreciated. Thank you!

        • 1. Re: Servlet won't compile
          sendres2 Newbie

          Sorry - Realized you can't see the xml text. Here it is:

          <!-- Global properties for this build -->
           <property name="target.classesdir" location="/WEB-INF/classes" />
           <property name="src.dir" location="" />
           <property name="target.jardir" location="/WEB-INF/lib" />
           <property name="webapp.dir" location="MetaDataRepository2/WEB-INF" />
           <property name="deploy.dir" location="deploy/" />
           <path id="compile.classpath" />
          
          <!-- Task 1: Compile the classes -->
           <target name="build-classes" description="compiles the classes">
           <mkdir dir="" />
           <javac destdir="" deprecation="true" debug="true" optimize="false">
           <classpath refid="compile.classpath" />
           <src>
           <pathelement location="" />
           </src>
           </javac>
           </target>


          • 2. Re: Servlet won't compile
            sendres2 Newbie

            If anyone else was having this problem, I've since figured it out. The classpath variable needed to be a direct reference, like so:

            <!-- Task 1: Compile the classes -->
             <target name="build-classes" description="compiles the classes">
             <mkdir dir="" />
             <javac destdir="" deprecation="true" debug="true" optimize="false">
             <classpath>
             <pathelement location="C:/Sun/AppServer/lib/j2ee.jar" />
             </classpath>
             <src>
             <pathelement location="" />
             </src>
             </javac>
             </target>