如何使用 Apache Tomcat 服务器运行 Eclipse 动态 Web 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15414586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:36:40  来源:igfitidea点击:

How to run an Eclipse Dynamic Web Application with Apache Tomcat Server?

eclipsetomcatservletsdeploymentlocalhost

提问by PhDeveloper

I tried running Apache Tomcat Server on Eclipse and got into the following problems:

我尝试在 Eclipse 上运行 Apache Tomcat Server 并遇到以下问题:

  1. The Catalina_Base is using a temporary location!
  2. I couldn't deploy the dependencies "jar files"!
  3. I got the following exception when running my web project:
  1. Catalina_Base 正在使用临时位置!
  2. 我无法部署依赖项“jar 文件”!
  3. 运行我的 Web 项目时出现以下异常:
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;] with root cause java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;

回答by PhDeveloper

I managed to solve the above 3 problems by doing the following steps:

我通过执行以下步骤设法解决了上述 3 个问题:

1- Double click your server (tomcat in this case) [if you can't see it go to Windows -> Show/View -> Other -> Server -> Servers]. Your server name will look something like: "Tomcat v7.0 Server at localhost".

1- 双击您的服务器(在本例中为 tomcat)[如果您看不到它,请转到Windows -> Show/View -> Other -> Server -> Servers]。您的服务器名称类似于:“Tomcat v7.0 Server at localhost”。

Double click the server and make sure the Server Locations is set to : "Use Tomcat installation (takes control of Tomcat installation)". If you can't edit the servers location: Stop the server, right-click the server and select Publish. If still you cant edit it:

双击服务器并确保服务器位置设置为:“使用 Tomcat 安装(控制 Tomcat 安装)”。如果您无法编辑服务器位置:停止服务器,right-click the server and select Publish. 如果仍然无法编辑它:

Right click the server --> Add and Remove and remove your project then publish it again.

右键单击服务器 --> 添加和删除并删除您的项目,然后再次发布它。

The reason for selecting "Use Tomcat installation" is that Catalina_Base will point to a temporary location and will look something like:

选择“使用 Tomcat 安装”的原因是 Catalina_Base 将指向一个临时位置,看起来像:

"-Dcatalina.base="C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1"

This will cause a 404 Error even when trying to open Apache Tomcat Start Page. When selecting "Use Tomcat Installation" the Catalina_Home and Catalina_Base values will be the same and both will point to the Tomcat Installation Directory: Example:

即使在尝试打开 Apache Tomcat 起始页时,这也会导致 404 错误。选择“使用 Tomcat 安装”时,Catalina_Home 和 Catalina_Base 值将相同,并且都指向 Tomcat 安装目录:示例:

-Dcatalina.base="C:\apache-tomcat-7.0.37" -Dcatalina.home="C:\apache-tomcat-7.0.37"

To see the Arguments:

要查看参数:

Double Click the Server then click on "Open launch configuration", the values will appear in the "Arguments" tab.

双击服务器,然后单击“打开启动配置”,值将出现在“参数”选项卡中。

2- When using dependencies (ex External Jar files), make sure the files are in : Web-Inf/lib and then add them to the class-path by doing the following:

2- 使用依赖项(例如外部 Jar 文件)时,请确保文件位于:Web-Inf/lib 中,然后通过执行以下操作将它们添加到类路径中:

Right-click the project --> Build-path --> Configure Build Path Select the "Libraries" tab Click Add External JARs and select the jar files in Web-Inf/lib

右键项目--> Build-path --> Configure Build Path 选择“Libraries”选项卡点击Add External JARs,选择Web-Inf/lib中的jar文件

Next you need to deploy dependencies: To do this:

接下来您需要部署依赖项:为此:

Right-Click the project -> Properties From the left side select "Deployment Assembly" On the right hand side click Add -> Java Build Path Entries -> Next Add all the jar files your project needs.

右键单击项目 -> Properties 从左侧选择“Deployment Assembly” 在右侧单击 Add -> Java Build Path Entries -> Next 添加项目所需的所有 jar 文件。

Otherwise, you'll get a class not found exception for the used jar files.

否则,对于使用的 jar 文件,您会得到一个 class not found 异常。

3- Make sure Web-Inf/lib does not contain any jar files from Apache Tomcat, as this will cause redundancies and will give the exception above!

3- 确保 Web-Inf/lib 不包含来自 Apache Tomcat 的任何 jar 文件,因为这会导致冗余并给出上述异常!