使用Maven的Java EE Web项目:找不到404错误消息

时间:2016-12-22 14:07:48

标签: java eclipse maven servlets java-ee

当我在eclipse Neon.2 4.6.2(针对Java EE IDE)上使用maven启动Web应用程序时,我遇到了一个很大的问题。

当我使用主servlet时,除了我的计算机上的http 404之外没有任何其他事情发生,没有任何错误消息。在控制台中,eclipse返回此错误:

  

GRAVE:Web应用程序中的Servlet [AccueilServlet] [/ GestionTrajet]   抛出load()异常java.lang.ClassNotFoundException:   presentation.AccueilServlet at   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)     在   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)     在   org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)     在   org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)     在   org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)     在   org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1133)     在   org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)     在   org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1571)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1561)     在java.util.concurrent.FutureTask.run(未知来源)at   java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at   java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at   java.lang.Thread.run(未知来源)

事实上,我已经尝试了几个可能性,最后一个是卸载所有东西(eclipse / jdk / jre / library等)并重做所有东西以获得一个干净的版本,但问题并非如此。改变,同样的错误。

在我朋友的计算机上,一切正常,他可以启动servlet(名为AccueillServlet.java),并且没有404错误。我们正在与Git合作,所以我有完全相同的项目版本。

的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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <welcome-file-list>
        <welcome-file>accueil.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>AccueilServlet</servlet-name>
        <servlet-class>presentation.AccueilServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>AccueilServlet</servlet-name>
        <url-pattern>/accueil</url-pattern>
    </servlet-mapping>

<!--    <servlet>
        <servlet-name>ListeServlet</servlet-name>
        <servlet-class>presentation.ListeServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ListeServlet</servlet-name>
        <url-pattern>/liste</url-pattern>
    </servlet-mapping> -->


</web-app>

Accueil.jsp

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Default title</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles/template.css" />
</head>
<style></style>

<body>
    <nav class="navbar navbar-default" id="DivNavBar">
        <div class="col-sm-3">
            <div class="navbar-header">             
                <img src="http://www.sodifrance.fr/sites/default/files/images/logos/logo-sodifrance-menu-business.png" alt="Sodifrance logo" />
            </div>
        </div>
        <div class="col-sm-6" id="DivFooter">               
        </div>
        <div class="col-sm-3"></div>
    </nav>

    <div class="col-sm-3"></div>
    <div class="col-sm-6">
        <h2 align="center">Programme collaboratif</h2>
        <h3>Merci de vous identifier</h3>

        <form  method="post">
        Identifiant
        <input id="login" type="text" name="login" /><br />
        Mot-de-Passe
        <input id="pwd" type="text" name="pwd" /><br /><br />
        <input type="submit" value="Se Connecter" />
        <br /><br />
        </form>     
    </div>
    <div class="col-sm-3"></div>

    <footer class="col-sm-12"> </footer>

</body>

</html>

AccueilServlet.java

package presentation;

import java.io.IOException;
import java.net.UnknownHostException;

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

import entite.Connexion;
import metier.ConnexionApplicationImpl;

/**
 * Servlet implementation class Accueil
 */
//@WebServlet("/accueil")
public class AccueilServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public AccueilServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doWork(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doWork(request, response);
    }

    private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ModelBean bean = new ModelBean("", "");
        String page ="/accueil.jsp";
        System.out.println("passage servlet accueil");

        // traitement des entrées
        if (request.getParameter("login") != null && request.getParameter("pwd") != null) {
            System.out.println("passage if login pwd différent null");
            Connexion connex = ConnexionApplicationImpl.getInstance().returnConnexion(request.getParameter("login"), request.getParameter("pwd"));

            if (connex.getLogin().equals("erreur") && connex.getNom().equals("erreur") && connex.getPwd().equals("erreur") && connex.getPrenom().equals("erreur")) {
                System.out.println("passage if erreur");
                request.getRequestDispatcher(page);
            } else {
                System.out.println("passage else login pwd OK");
                bean = new ModelBean(request.getParameter("login"),request.getParameter("pwd"));
                page = "liste";
                System.out.println(page);
                response.sendRedirect("http://localhost:8080/GestionTrajet/liste");
                request.getRequestDispatcher(page);
            }

            // a = Integer.parseInt(request.getParameter("A"));
            // b = Integer.parseInt(request.getParameter("B"));
            // c = a + b;
            // bean = new ModelBean(a.toString(), b.toString(), c.toString());

        }

        // passage à la vue
        System.out.println(page);
        request.setAttribute("bean", bean);
        request.getRequestDispatcher(page).forward(request, response);
    }

}

的pom.xml 更新:2016年12月23日

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sodifrance</groupId>
    <artifactId>GestionTrajet</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>GestionTrajet Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Dependendance MongoDB -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
            <version>3.0.4</version>
        </dependency>

        <!-- Dependendance JEE -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>

        <!-- standard.jar -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Dependendance JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.2</version>
        </dependency>

        <!-- Bug JSF -->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Dependendance Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.4.RELEASE</version>
        </dependency>

        <!-- Dependendance fonctionnement tomcat -->
        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
            <version>2.1</version>
        </dependency>

    </dependencies>
    <build>

        <finalName>GestionTrajet</finalName>
    </build>
</project>

目录

My project Directory

我是Java EE技术的新手,但是从我的pov来看,看起来Maven做错了。我已经尝试过与我的朋友完全相同的eclipse版本,它根本没有工作,再次做同样的错误。

如果它是源代码中的问题,如果你能给我一些指示可以帮助我找到主要问题。我不是sur,但我认为问题来自eclipse,可能是库或maven,但不是来自代码。

(先谢谢你的帮助,对不起英语错误)

编辑2016年12月23日

首先,感谢您的回答,我纠正了依赖问题,我不知道这可能是一个问题:)

当我使用&#34; Debug As:Maven Test&#34;时,我发现了另一个错误。在我的项目上,看起来它无法编译,因为他无法找到编译器(参见下面的错误)

Message error

我试图编辑eclipse.ini并给他jdk位置(我可能做错了,我只是尝试了一些东西),但它返回了同样的错误。

0 个答案:

没有答案