简体   繁体   中英

What is correct way to import java web maven project to eclipse?

Sorry, I'm really new in eclipse and java servlets. I have read this question Can Eclipse import a Maven Web project as a "Dynamic Web Application"? , it was really helpful for me.

I did import project as existing maven project. 在此处输入图片说明

I have changed the project facets (but there was some problems with Dynamic Web Module version , i have changed it to 2.5), and now i can use "run on server" option. I use tomcat 6.

But there was some problems with my web.xml location, in my imported project web.xml file was in root/src/main/webapp/WEB-INF and eclipse can't find it in root/WebContent/WEB-INF so after some changes web.xml file have been detected, and some servlets have appeared

在此处输入图片说明

but when I'm trying to run any servlet, appear similar errors

javax.servlet.ServletException: Wrapper cannot find servlet class com.games.GulliverTravel.servlets.InitializeGameServlet or a class it depends on
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:680)
root cause

java.lang.ClassNotFoundException: com.games.GulliverTravel.servlets.InitializeGameServlet
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:680)

There is my pom file

<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>ProjectName</groupId>
  <artifactId>ProjectName</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>ProjectName Backend</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.3.1</version>
        <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>ProjectName</finalName>
  </build>
</project>

I can't understand why it happens, because when I did this before on another computer all was fine, and it imported correctly, without some problems. Please, help me. Can it be related on changing location of web.xml file? Do you have any idea how to fix these roblems? Thank you.

Update: Also repository from where I cloned the project have not .project file, there is only classes, web.xml and pom files.

Import existing maven project is right option IMO

this will only ensure you dont loose your source/test folder structure and continue to build using Maven.

or you can use mvn eclipse:eclipse command at command line, which will generate eclipse specific files for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM