简体   繁体   English

Maven,Eclipse,Spring,Tomcat和ClassNotFoundException SpringServletContainerInitializer

[英]Maven, Eclipse, Spring, Tomcat and ClassNotFoundException SpringServletContainerInitializer

my Maven Eclipse Project use Spring 4.1.6.RELEASE, java 8, and Tomcat 8 server for deploy. 我的Maven Eclipse Project使用Spring 4.1.6.RELEASE,java 8和Tomcat 8服务器进行部署。 When i built project using console "mvn package" and deploy .war file by /manager it works fine. 当我使用控制台“ mvn软件包”构建项目并通过/ manager部署.war文件时,它工作正常。 But when i want ot use Eclipse and its "Run on Server" option it throws sth like this: 但是,当我想使用Eclipse及其“在服务器上运行”选项时,它会抛出如下信息:

ava.io.IOException: java.lang.ClassNotFoundException: org.springframework.web.SpringServletContainerInitializer...

At the end in console i can see 在控制台的最后,我可以看到

May 15, 2015 10:39:08 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1424 ms

but i am not able to open tomcat's manager or my website (HTTP Status 404) 但我无法打开tomcat的管理员或我的网站(HTTP状态404)

I'm pretty sure that there is problem with Eclipse Build path or Assembly Dependency but i have no idea what to do. 我很确定Eclipse Build路径或Assembly Dependency存在问题,但是我不知道该怎么做。

pom.xml(dependencies): pom.xml(依赖关系):

<properties>
  <spring.version>4.1.6.RELEASE</spring.version>
</properties>
<build>
  <sourceDirectory>src</sourceDirectory>
  <plugins>
    <plugin>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
      </configuration>
    </plugin>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
  </plugins>
</build>
<dependencies>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
  </dependency>
<!-- Spring dependencies -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
  </dependency>

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
  </dependency>

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
  </dependency>
</dependencies>

Edit 编辑

Before error message there are two lines: 错误消息之前有两行:

May 15, 2015 11:38:19 AM org.apache.catalina.startup.ContextConfig processServletContainerInitializers
SEVERE: Failed to process JAR found at URL [/aaaa] for ServletContainerInitializers for context with name [{1}]

Possible solution 可能的解决方案

  1. Open the project's properties (eg, right-click on the project's name in the project explorer and select "Properties"). 打开项目的属性(例如,在项目浏览器中右键单击项目的名称,然后选择“属性”)。
  2. Select "Deployment Assembly". 选择“部署程序集”。
  3. Click the "Add..." button on the right margin. 单击右边的“添加...”按钮。
  4. Select "Java Build Path Entries" from the menu of Directive Type and click "Next". 从“指令类型”菜单中选择“ Java构建路径条目”,然后单击“下一步”。
  5. Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish". 从Java Build Path Entries菜单中选择“ Maven Dependencies”,然后单击“ Finish”。

The tomcat manager issue is because Eclipse doesn't copy the ROOT and manager directories from Tomcat's webapps to wtpwebapps. tomcat管理器问题是因为Eclipse不会将ROOT和manager目录从Tomcat的web应用程序复制到wtpwebapps。 Wtpwebapps is a separate folder for Eclipse's own webbapp deployments ie when you deploy a webapp directly via eclipse. Wtpwebapps是Eclipse自己的webbapp部署的单独文件夹,即当您直接通过eclipse部署webapp时。 Make sure you copy everything inside webapps to wtpwebapps manually. 确保手动将webapp内的所有内容复制到wtpwebapps。

Ok, thank's for all of answers. 好的,谢谢您的回答。 Converting to Maven Project removed EAR Library and Webapp Libraries from project. 转换为Maven Project已从项目中删除了EAR库和Webapp库。 The solution was to add them again. 解决的办法是再次添加它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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