为什么我在使用" ant"时会出现导入错误?命令build.xml?

时间:2017-07-20 15:18:50

标签: xml ubuntu tomcat servlets ant

我正在使用' ant'命令在包含build.xml的目录中,但我在使用import语句时遇到错误。当它到达这一行时,

    <!-- 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>

它引用了一个java文件

    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
{ . . . .

我尝试编译java文件时遇到以下错误:

     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.

我安装了Tomcat和JRE 8,并且我正在运行Ubuntu但是构建失败了。我不知道为什么我有错误。 感谢

编辑* 类路径在build.xml文件中定义如下:

    <!-- 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>

2 个答案:

答案 0 :(得分:1)

跑步:

$ export CATALINA_HOME=/opt/tomcat
$ ant

答案 1 :(得分:0)

需要根据我的安装参数设置类路径。 那是:

    <!-- 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>

我对Tomcat的安装没有/common。所以改成它:

    <!-- 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>

修复了问题。