【问题标题】:Not able to deploy project无法部署项目
【发布时间】:2014-09-24 20:52:26
【问题描述】:

我有我通过正确配置的侦听器类配置的数据库连接 在DD中

    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

   <listener>
        <listener-class>contpack.startL</listener-class>
    </listener>
    <context-param>
        <param-name>username</param-name>
        <param-value>root</param-value>
    </context-param>
    <context-param>
        <param-name>password</param-name>
        <param-value>root</param-value>
    </context-param>
    <context-param>
        <param-name>url</param-name>
        <param-value>jdbc:mysql://localhost:3306/mysql</param-value>
    </context-param>

    <servlet>
        <servlet-name>hell</servlet-name>
        <servlet-class>com.contpack.Dbc</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hell</servlet-name>
        <url-pattern>/Dbc</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>home.html</welcome-file>
    </welcome-file-list>
</web-app>

但我仍然无法部署项目,服务器日志显示找不到 startL.java 侦听器类为什么会这样,因为配置名称正确 侦听器类是:

        package com.contpack;

        import javax.servlet.*;
        import javax.servlet.http.*;
        import model.Database;


        public class startL implements ServletContextListener {

        public void contextInitialized(ServletContextEvent event)
        {
                ServletContext sc = event.getServletContext();
                String url = sc.getInitParameter("url");
                String user_name = sc.getInitParameter("username");
                String password = sc.getInitParameter("password");
             //   String database = sc.getInitParameter("database");
                Database db = new Database(url,user_name,password);
            //System.out.println("in the listener!!");
                sc.setAttribute("db", db);

        }

        public void contextDestroyed(ServletContextEvent event)
        {

        }
    }

服务器日志的堆栈跟踪是:

    [2014-08-01T20:53:59.112+0530] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] 
    [tid: _ThreadID=34 _ThreadName=admin-listener(3)]
    [timeMillis: 1406906639112] [levelValue: 1000]
    [[Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: contpack.startL.java]]

如果我删除 Listener 标记,则应用运行正常

【问题讨论】:

  • 张贴web.xml和监听类请不要图片
  • @M.Sharma 你能帮我吗...
  • 尝试为您的侦听器类遵循 java 命名约定
  • @Nik6019 嗨,对不起,看到你的消息顺便说一句jjd 很好地给了你答案,你的包名是com.contpack 所以将&lt;listener-class&gt;contpack.startL&lt;/listener-class&gt; 更改为com.contpack.startL

标签: java servlets web-applications netbeans glassfish


【解决方案1】:
...
<listener>
    <listener-class>contpack.startL</listener-class>
</listener>
...

你的听众在包里

package com.contpack;

这意味着您的听众完全限定名称是

com.contpack.startL

因此,设置正确的侦听器类会有所帮助。您的 web.xml 应如下所示

...
<listener>
    <listener-class>com.contpack.startL</listener-class>
</listener>
...

遵循 java 命名约定总是一个好主意

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2017-09-01
    • 2021-02-25
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多