- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在编写一个脚本来构建项目、创建 War 文件并将其部署到 Tomcat 上。我在执行脚本时收到以下错误,特别是在 javac 命令期间。请注意,我尝试在没有 Eclipse 的情况下进行此操作,因此无法直接集成 Tomcat 7。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:ant="antlib:net.sf.antcontrib" name="Build Script For Deploy" default="NN-build" >
<!-- This sript will read required proeprty values from below properties file -->
<property file="upgrade.properties" />
<target name="NN-build" depends="compile" description="NN VM build target with CDT update" />
<!--Keeping all the required jar files to classpath.
All the ANT tasks used in the rest of the script will be executed from below jar files Hence they need to be on classpth. -->
<path id="svnant.classpath">
<fileset dir= "${lib.dir}" >
<include name= "**/*.jar" />
</fileset>
</path>
<path id = "catalina-ant-classpath">
<fileset dir="${appserver.lib}">
<include name = "catalina-ant.jar" />
</fileset>
</path>
<taskdef name="install" classname = "org.apache.catalina.ant.DeployTask">
<classpath refid = "catalina-ant-classpath" />
</taskdef>
<!-- Defining all the required ANT tasks which will be used in the rest of the script -->
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" />
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${lib.dir}/ant-contrib-1.0.jar"/>
</classpath>
</taskdef>
<property name="src.dir" location="${dest.home}/src" />
<property name="classes.dir" location="${dest.home}/build/classes"/>
<property name="dist.dir" location="${dest.home}/WebContent/WarFile" />
<path id="compile.classpath">
<fileset dir="${dest.home}/WebContent/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
<!-- Target for deleting the existing directories-->
<target name="clean">
<delete dir="${classes.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Target for creating the new directories-->
<echo>....Creating new directories.... </echo>
<target name="makedir">
<mkdir dir="${classes.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Target for compiling the java code-->
<target name="compile" depends="clean, makedir">
<javac destdir="${classes.dir}" debug="true"
deprecation="false" optimize = "false" failonerror = "true" >
<src path="${src.dir}" />
<classpath refid="compile.classpath" />
</javac>
</target>
</project>
java:43: error: cannot find symbol ServletContext context = request.getServletContext(); [javac] ^
[javac] symbol: method getServletContext()
[javac] location: variable request of type HttpServletRequest
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
BUILD FAILED
C:\task\task-upgrade.xml:97: Compile failed; see the compiler error output for
details.
当我在 Eclipse 中导入项目时,我收到了同样的错误,但添加服务器运行时作为 Tomcat7 修复了它。
最佳答案
构建 J2EE 应用程序时,用于编译的类路径需要与运行时使用的类路径不同。由于您的 Web 应用程序使用 J2EE API,因此需要针对它进行编译。但是一旦部署,这些 API 将由您选择的容器(此处为 Tomcat)提供,因此它们不应该成为您的 Web 应用程序的一部分。
因此,在您的具体示例中,您需要 javax servlet-api。它的 jar 需要添加到您的编译类路径中,但不要放入 WEB-INF/lib
文件夹中。
以下是可能适合您需要的 jar 列表:
https://search.maven.org/search?q=g:javax.servlet%20AND%20a:javax.servlet-api&core=gav
https://search.maven.org/search?q=g:org.apache.tomcat%20AND%20a:tomcat-servlet-api&core=gav
关于java - 构建时找不到符号 request.getServletContext(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58954456/
这个问题在这里已经有了答案: Different ways to get Servlet Context (1 个回答) 关闭 6 年前。 我有 SampleServlet 类,在其中我重写了 do
我已经看到您也可以直接调用 getservletcontext() 并且也像这样 req.getsession().getservletcontext() 。 这两者有什么区别,我应该使用哪一个?有没
我有一个 Tomcat 6 实例在我的本地机器上运行。 我对其配置进行了以下更改: 在/conf/context.xml – 如下更改标签 在/conf/server.xml – 更改标签如下 假
html Murach's Java Servlets and JSP Thanks for joining our email list H
我知道这个问题已被问过一百万次并且有 500 万个答案 - 一些或其中的信息非常丰富。这些都没有解决这个问题。 我的目标与许多其他目标类似 - 我想访问网络应用程序运行时环境中的文件 - 图像、svg
我是一名菜鸟程序员,正在为 tomcat 在 eclipse 上开发我的第一个动态 Web 应用程序。它与 mySQL 数据库通信并修改一些模板文件并将它们另存为新文件。该应用程序需要便携。我知道绝对
我正在尝试使用 getServletContext().getRealPath( "/") ,但我不断收到此错误: 找不到符号符号:方法 getServletContext()位置:接口(interf
这个问题已经有答案了: Recommended way to save uploaded files in a servlet application (2 个回答) 已关闭 8 年前。 这是我的情况
背景:我想通过使用 Velocity 和 servlet 来学习 Web 开发。我使用 getServletContext().getRealPath("/") 查找 WEB-INF 的路径以及存储在
以下代码是我的示例 servlet 应用程序 protected void doGet(HttpServletRequest request, HttpServletResponse response
我要获取servletContext在 Java 类中从 WEB-INF 读取文件目录。我用 HttpServlet 扩展了我的类(class)并尝试获取如下代码中的上下文,但 servlet 配置返
当尝试像这样设置 Context 属性时: void init() { String testing = new String(); testing = "This is a test
getServletContext.getRealPath("string") 抛出空指针异常。我如何使用它来获取真实路径? public void doGet(HttpServletRequest
我一直在编写一个脚本来构建项目、创建 War 文件并将其部署到 Tomcat 上。我在执行脚本时收到以下错误,特别是在 javac 命令期间。请注意,我尝试在没有 Eclipse 的情况下进行此操作,
本文整理了Java中org.directwebremoting.WebContext.getServletContext()方法的一些代码示例,展示了WebContext.getServletCont
我的生产应用程序位于某个域名 ABC.com 上。在我的代码中,我根据某些操作将用户重定向到其他页面 response.sendRedirect(request.getServletContext()
我正在努力将现有应用程序从 Spring Boot 1.5 升级到 2.1。此应用程序作为 WAR 文件部署在现有 Tomcat 实例中。 我已经克服了大部分迁移障碍,但现在当 Thymeleaf 的
ServletContext context=getServletContext(); 这里 ServletContext 是接口(interface)。 Context是ServletContext
我有一个MainServletContext,它实现了存储属性的ServletContextListener public void contextInitialized(ServletContext
下面是 GenericServlet 类中的 2 个方法, public ServletConfig getServletConfig() { return this.conf
我是一名优秀的程序员,十分优秀!