Issue
I'm using the 'ant' command in a directory containing a build.xml but I'm getting errors with import statements. When it gets to this line,
<!-- compile.gui -->
<target name="compile.gui" depends="test.properties,compile.api">
<javac srcdir="${src}" destdir="${build.classes}"
classpathref="gui.class.path" debug="on" target="1.8" includeantruntime="false">
<include name="eu/lt4el/gui/**" />
</javac>
</target>
it references a java file
package eu.lt4el.gui;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import eu.lt4el.common.DocumentStatus;
import eu.lt4el.AppInterface;
import eu.lt4el.defcontext.Definition;
import org.apache.log4j.Logger;
public class LTStartPage extends HttpServlet
{ . . . .
and I get the following errors when it tries to compile the java file:
compile.gui:
[javac] Compiling 1 source file to /home/ufuoma/Downloads/ltserver/build/classes
[javac] /home/ufuoma/Downloads/ltserver/src/eu/lt4el/gui/LTStartPage.java:3: error: package javax.servlet does not exist
[javac] import javax.servlet.*;
[javac] ^
[javac] /home/ufuoma/Downloads/ltserver/src/eu/lt4el/gui/LTStartPage.java:4: error: package javax.servlet.http does not exist
[javac] import javax.servlet.http.*;
[javac] ^
[javac] /home/ufuoma/Downloads/ltserver/src/eu/lt4el/gui/LTStartPage.java:13: error: cannot find symbol
[javac] public class LTStartPage extends HttpServlet
[javac] ^
[javac] symbol: class HttpServlet
[javac] /home/ufuoma/Downloads/ltserver/src/eu/lt4el/gui/LTStartPage.java:17: error: cannot find symbol
[javac] protected HttpSession session;
[javac] ^
[javac] symbol: class HttpSession
[javac] location: class LTStartPage
[javac] /home/ufuoma/Downloads/ltserver/src/eu/lt4el/gui/LTStartPage.java:33: error: cannot find symbol
...
...
[javac] 17 errors
BUILD FAILED
/home/ufuoma/Downloads/ltserver/build.xml:305: Compile failed; see the compiler error output for details.
I have Tomcat and JRE 8 installed and I'm running Ubuntu but the build fails. I don't know why I'm having the erros. Thanks
Edits* The class path is defined as follows in the build.xml file:
<!-- class path for gui -->
<path id="gui.class.path">
<pathelement path="${env.CATALINA_HOME}/common/lib/servlet-api.jar"/>
<pathelement path="${lib}/log4j-1.2.14.jar"/>
</path>
Solution
The class path needed to be set right according to my installation parameters. It was:
<!-- class path for gui -->
<path id="gui.class.path">
<pathelement path="${env.CATALINA_HOME}/common/lib/servlet-api.jar"/>
<pathelement path="${lib}/log4j-1.2.14.jar"/>
</path>
And my installation for Tomcat did not have a /common
. So changing it to:
<!-- class path for gui -->
<path id="gui.class.path">
<pathelement path="${env.CATALINA_HOME}/lib/servlet-api.jar"/>
<pathelement path="${lib}/log4j-1.2.14.jar"/>
</path>
fixed the problem.
Answered By - TheSoldier
Answer Checked By - Timothy Miller (JavaFixing Admin)