Eclipse Maven web application - can not run on ser

2019-03-15 01:10发布

问题:

I have an maven eclipse webapp project that I was able to right click and 'Run on server' and it would deploy on tomcat. I recently did a 'maven -> Update project conifgurations' and I now can NOT deploy and run the project as a webapp. Has anyone seen this before? The only output from tomcat is as follows - it doesnt even look like its trying to deploy the application.

Apr 14, 2010 3:58:54 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Apr 14, 2010 3:58:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:taac-web' did not find a matching property.
Apr 14, 2010 3:58:54 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 14, 2010 3:58:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 402 ms
Apr 14, 2010 3:58:54 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 14, 2010 3:58:54 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Apr 14, 2010 3:58:54 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 14, 2010 3:58:54 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 14, 2010 3:58:54 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/14  config=null
Apr 14, 2010 3:58:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 247 ms

The POM is still set to WAR, but after cleaning the project I am now getting ClassNotFoundExceptions for libraries that are being included as Maven Dependencies:

SEVERE: Error configuring application listener of class org.springframework.security.web.session.HttpSessionEventPublisher
java.lang.ClassNotFoundException: org.springframework.security.web.session.HttpSessionEventPublisher

Here is my POM:

<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>com.cable.wuntee.neto.nse</groupId>
  <artifactId>taac-web</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>taac-web JEE5 Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.16</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>1.3.0.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap</artifactId>
        <version>1.3.0.RELEASE</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-ldap</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-cada</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-sams</artifactId>
        <version>2.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
    <finalName>taac-web</finalName>
  </build>
</project>

回答1:

I found the answer on

Tomcat & Spring Web - Class Not Found Exception org.springframework.web.context.ContextLoaderListener

you need to push Maven dependencies to the server when the project is published to it.

Right Click on your web project in Project Explorer -> select 'Properties'. Under project properties, select 'Deployment Assembly'.

The Deployment Assembly property page shows the content that will be published as a assembled artifact by Eclipse to the server. You need to tell Eclipse that you want all your Maven dependencies to be published too.

To do that, click 'Add' button, then select 'Java Build Path Entries'. Click Next and select Maven Dependencies. This will publish the Maven dependency JAR files to the lib folder when Eclipse publishes your project to WST server



回答2:

Three possible solutions. I've used all three depending on how it went wrong.

  1. I resolved this by removing the spring security dependencies from my POM (I only have spring-security-taglibs and spring-security-config which pull in everything else I need), saved the POM, let Maven do it's stuff and then added them back in again, let Maven get the dependencies again and restarted the server in Eclipse. When the problem is happening, the Maven dependencies directory in the Eclipse project seems to be missing the spring-security-web artifact (which holds org.springframework.security.web.session.HttpSessionEventPublisher). For me, it only happens when I start Eclipse after rebooting my PC so I'm assuming it's Windows (Vista) and the Eclipse M2Eclipse plugin not playing nicely on file locking or something.

  2. Alternative solution (the problem happened again and previous solutions wouldn't work). This time, I deleted the org/springframework directory from my local maven repository (the one in Eclipse Window->Preferences->Maven->User Settings). Then, update Maven dependencies and wahey here we go again.

  3. If you've done "Maven->Update Project Configuration" and this happens it may well be because your "Deployment Assembly" settings aren't including the Maven dependencies. Go to project->properties->deployment assembly. Check that Maven Dependencies is in there and haas a deploy path of /WEB-INF/lib. If not, click on add and find it under the Java build path option. If it's not there, your build path is probably corrupted too (although that's never happened to me).



回答3:

Maybe you changed the <packaging> from war to something else per accident. Can you show your POM?

Can you also confirm that you have the Maven WTP Integration for WTP installed (this is improbable but maybe you installed the latest version of M2Eclipse without this extra and somehow, things were working until you updated the project configuration )?



回答4:

I had that weird compilation errors you had on the WAR project. From some reason the classpath was changed somehow and it ignored other projects in my workspace which the WAR was dependent upon.

The only solution which eventually worked was to erase my workspace, and on each project delete .classpath, .project and .settings. Starting from a new workspace solved it.

I did find a bug mentioning something similar to this in Maven WTP bug tracker, but I didn't get enough votes to get fixed I guess.



回答5:

Under project properties, go to "facets", press convert to something something, enable dynamic web module and press apply.



回答6:

None of these helped - I ended up just disabling workspace resolution, and dealing with installing the workspace dependancies when they were out of date.



回答7:

Alternative solution (the problem happened again and previous solutions wouldn't work).

This time, I deleted the org/springframework directory from my local maven repository (the one in Eclipse Window->Preferences->Maven->User Settings). Then, update Maven dependencies and wahey here we go again.



回答8:

I had the same problem today, for me it helps to reinstall apache in eclipse an rebuilding/refreshing the project afterwards



回答9:

Okay, I've struggled with this a bit as well. I don't think there's much of a definitive answer and for a while I would just delete the project and re-import it since that would work every time.

Today I found that it started to work again after running a maven clean on the project (mvn clean from the command line, for example). Give that a try to see if that will work for you.

This is NOT equivalent to the eclipse clean as it only deletes a selected few folders from the target directory, not the whole thing.



回答10:

I've run into this issue every so often, quick fixes are:

  • Right click project -> Maven -> Update Project...
  • Eclipse Servers tab: stop server, Right click Tomcat v# -> Clean... -> OK

Here are the troubleshooting steps I use to see what Eclipse is actually deploying when it runs tomcat. This is current as of Mars and Neon. (these steps assume you have run your project at least once using "Run on server...")

  1. Pull up the settings for running your project on tomcat:
    Right click project -> Run As -> Run Configurations...
  2. Go to the arguments tab and look in VM arguments, you will see something like this: Look for the value of -Dwtp.deploy. For me it was

D:\code\workspaceNeon\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps

  1. That directory contains the standard webapp deployment structure. Open that directory in your OS file explorer and examine the contents. When I looked in my WEB-INF/lib, I saw most of my dependencies were missing
  2. Be sure to exit out of that directory when you are done, otherwise eclipse will get errors trying to modify/update it

Now it's time to fix the problem. Let's see what Eclipse is supposed to be deploying:

  1. Open the Deployment Assembly settings for your project:

    Right click project -> Properties -> Deployment Assembly

    1. Maven Dependencies is the critical item above. If this is missing, close out of the dialog and do a maven update: Right click project -> Maven -> Update Project...

    2. Now that we've made updates, let's clear out the server working directory manually and republish. This may not always be necessary, but is a good way to ensure everything is in sync between what's shown in Deployment Assembly and what is actually deployed:

      • In eclipse go to the Servers tab. If you don't see it in your current eclipse layout, do Window menu -> Show View -> Other.. -> search for "Servers"
      • Right click Tomcat v#... and select "Clean...". Click OK in the confirmation dialog
      • Right click Tomcat v#... and select "Publish"
      • Start the server and test. If still have problems, go back to the wtp.deploy directory and inspect to see what's wrong

Good luck!