ant tomcat cant编译缺少的HttpServlet包

时间:2018-05-03 14:15:56

标签: ant

我正在尝试将网络应用程序部署到tomcat7。我读到tomcat提供了servlet库,并通过查看/ usr / share / tomcat7 / lib来确认。其中包含:

  

servlet-api.jar,jsp-api.jar,annotations-api.jar,httpclient-4.5.3.jar   httpclient-cache-4.5.3.jar,httpcore-4.4.6.jar,httpclient-4.5.3.jar,   GSON-2.6.2.jar

build.xml的相关(我认为)部分是:

  <path id="compile.classpath">
    <!-- Include all JAR files that will be included in /WEB-INF/lib -->
    <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->
    <pathelement location="${basedir}/lib/*"/>
    <!-- Include all elements that Tomcat exposes to applications -->
    <fileset dir="${catalina.home}/bin">
      <include name="*.jar"/>
    </fileset>
    <pathelement location="${catalina.home}/lib"/>
    <fileset dir="${catalina.home}/lib">
      <include name="*.jar"/>
    </fileset>
  </path>

应用程序怎么不编译说未知符号?我还在项目文件夹/ lib中有这些文件:

symbol:   class HttpSession
    [javac]   location: class QuestionPageServlet
    [javac] /var/lib/tomcat7/webapps/FlashcardShark/src/flashcardshark/servlet/QuestionPageServlet.java:53: error: cannot find symbol
    [javac]             String responseMessage = new Gson().toJson("card successfully udpated");
    [javac]                                          ^
    [javac]   symbol:   class Gson
    [javac]   location: class QuestionPageServlet
    [javac] /var/lib/tomcat7/webapps/FlashcardShark/src/flashcardshark/servlet/QuestionPageServlet.java:56: error: cannot find symbol
    [javac]             response.setStatus(HttpServletResponse.SC_ACCEPTED);
    [javac]                                ^
    [javac]   symbol:   variable HttpServletResponse
    [javac]   location: class QuestionPageServlet
    [javac] /var/lib/tomcat7/webapps/FlashcardShark/src/flashcardshark/servlet/QuestionPageServlet.java:66: error: cannot find symbol
    [javac]            HttpSession session = request.getSession();
编辑:我从oracles网站下载javaee-8相应的J2EE_HOME,并将以下内容添加到构建文件的上一部分,但仍然无法编译:

<path id="compile.classpath">
    <pathelement location="${basedir}/lib/*"/>
    <fileset dir="${catalina.home}/bin">      <include name="*.jar"/>
    </fileset>
    <pathelement location="${catalina.home}/lib"/>
    <fileset dir="${catalina.home}/lib">
      <include name="*.jar"/>
    </fileset>
    <pathelement path = "${env.J2EE_HOME}/${j2ee.jar}"/>
   <fileset dir = "lib">
      <include name = "**/*.jar"/>
   </fileset>
  </path>

1 个答案:

答案 0 :(得分:0)

我是编写ant构建脚本的新手:但这是我为编译而做的:

<javac srcdir="${src.home}"
          destdir="${build.home}/WEB-INF/classes"
            debug="${compile.debug}"
           includes="${basedir}/lib/*"
      deprecation="${compile.deprecation}"
         optimize="${compile.optimize}">

包含选项就是它做了什么。