gpt4 book ai didi

eclipse - java.lang.NoClassDefFoundError : org/eclipse/wst/web/internal/deployables/IFlatDeployable 错误

转载 作者:行者123 更新时间:2023-11-28 22:38:16 24 4
gpt4 key购买 nike

Servlet 无法在 Eclipse Juno for Java EE 中新创建的动态 Web 项目中运行。这是从头开始的过程:

  • 我下载了 Eclipse EE (Juno),没有更改任何默认配置
  • 我下载了最新的 Tomcat (7.0.30)
  • Preferences > Server > Runtime Environments 我添加了新的 Apache Tomcat v7.0
  • 我创建了名为 UniBudget 的新动态 Web 项目(上下文根:budget)
  • 我添加了新文件(index.jps,里面有“it works!”)

此刻,在将项目添加到服务器并运行它之后,我可以在屏幕上看到“它工作了!”。因此,部署有效。

  • 接下来我添加了 servlet 文件(control.Controller.java):

    package control;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    @WebServlet({ "/Controller", "*.do" })
    public class Controller extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public Controller() {
    super();
    }

    protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    System.out.println("doGet()");
    }

    protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    System.out.println("doPost()");
    }

    }
  • 我将 index.jsp 改成了这样,仅此而已:

    <jsp:forward page="/departments.do"/>
  • 当然还有 web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>UniBudget</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <!-- servlet definition -->
    <servlet>
    <servlet-name>Do</servlet-name>
    <servlet-class>control.Controller</servlet-class>
    </servlet>
    <!-- servlet mapping -->
    <servlet-mapping>
    <servlet-name>Do</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>Do</servlet-name>
    <url-pattern>/Controller</url-pattern>
    </servlet-mapping>
    </web-app>
  • 生成的 .class 文件必须在 WEB-INF/classes 中,对吗?这就是我读到的。所以: Configure Build Path > Source 选项卡 > Browse > 我在 WEB-INF 中创建了 classes 文件夹(在 Advanced我链接到文件系统中的文件夹:.../UniBudget/build/classes)

  • 这是项目中的文件层次结构:

file hierarchy in project

  • 我清理并构建了 UniBudget 项目并重新发布到服务器。清理服务器。

  • 我想我现在可以工作了(我的意思是在控制台中显示“doGet()”“doPost()”)。但是我没有在控制台中打印输出,而是收到了这个错误:

    HTTP Status 404 - /budget/departments.do

    --------------------------------------------------------------------------------

    type: Status report

    message: /budget/departments.do

    description: The requested resource is not available.
  • 当我尝试直接访问 http://localhost:8080/budget/Controller(无需从 index.jsp 重定向)时,也会发生同样的情况

看起来 Eclipse 根本看不到 servlet!你能指出我在哪里犯了错误吗?我现在好几个小时都想不通了。


编辑:

去掉多余注解(@WebServlet)后,又出现一个错误:

HTTP Status 503 - Servlet Do is currently unavailable

--------------------------------------------------------------------------------

type Status report

message Servlet Do is currently unavailable

description The requested service is not currently available.

控制台错误:

wrz 24, 2012 9:34:15 PM org.apache.catalina.core.ApplicationDispatcher invoke
WARNING: Servlet Do is currently unavailable

不多。但仅此而已。


编辑:

我发现这里又发生了另一个错误。我什至不确定如何重新创建它,但至少这个提供了更多日志信息:

HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 3

--------------------------------------------------------------------------------

type: Exception report

message: An exception occurred processing JSP page /index.jsp at line 3

description: The server encountered an internal error that prevented it from fulfilling this request.

exception:

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 3

1: <%@ page language="java" contentType="text/html; charset=UTF-8"
2: pageEncoding="UTF-8"%>
3: <jsp:forward page="/departments.do"/>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause:

javax.servlet.ServletException: Error instantiating servlet class control.Controller
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause:

java.lang.ClassNotFoundException: control.Controller
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

编辑:

项目右键单击 > 导出 > WAR 文件 期间出错:

java.lang.NoClassDefFoundError: org/eclipse/wst/web/internal/deployables/IFlatDeployable
at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.getModuleParticipants(JavaEEComponentExportOperation.java:77)
at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.getParticipants(JavaEEComponentExportOperation.java:43)
at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.createFlatComponentArchiver(JavaEEComponentExportOperation.java:91)
at org.eclipse.jst.j2ee.internal.archive.operations.ComponentExportOperation.export(ComponentExportOperation.java:191)
at org.eclipse.jst.j2ee.internal.archive.operations.ComponentExportOperation.execute(ComponentExportOperation.java:136)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl$1.run(DataModelPausibleOperationImpl.java:385)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:410)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:360)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.doExecute(DataModelPausibleOperationImpl.java:247)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.executeImpl(DataModelPausibleOperationImpl.java:219)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.cacheThreadAndContinue(DataModelPausibleOperationImpl.java:89)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.execute(DataModelPausibleOperationImpl.java:207)
at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard$1CatchThrowableRunnableWithProgress.run(DataModelWizard.java:220)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

最佳答案

java.lang.NoClassDefFoundError: org/eclipse/wst/web/internal/deployables/IFlatDeployable

糟糕。这是一个非常严重的错误,这个类是 Eclipse 内部的。这曾被报告为 Eclipse issue 388698 ,但不幸的是,它已作为 WORKSFORME 关闭。毕竟,这似乎是一个特定于环境/平台/配置的问题。我会考虑重新发布相同的问题以及尽可能多的有关所用环境的详细信息(操作系统品牌/版本、JRE/JDK 品牌/版本、硬件规范等)。

我个人还没有尝试过 Juno(我通常等待 SR1 在冬天左右发布,以便涵盖所有主要的初期问题),但是如果完全删除 Eclipse 安装并重新解压缩它不起作用,那么我建议尝试退回到以前的 Eclipse 版本,即 Indigo SR2 .确保为您的平台下载正确的版本(32 位与 64 位)。

关于eclipse - java.lang.NoClassDefFoundError : org/eclipse/wst/web/internal/deployables/IFlatDeployable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12566170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com