12

I had a problem similar to this (java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener), the difference in my case is that the common fix (adding Maven Dependencies to Deployment Assembly) is only temporary and it breaks every time I do a Maven Update, which is not too frequent, but just enough to be a real nuisance.

Is there a permanent fix?

DETAILS

This is the error I get enter image description here

And I fix it by going here: enter image description here

Then here: enter image description here

and finally here... enter image description here

Here's what it looks like once it's fixed: enter image description here

Here is my pom.xml:

<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>ctc.web.proyect</groupId>
  <artifactId>front.web</artifactId>
  <packaging>war</packaging>
  <version>0.2.5</version>
  <name>front.web</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <javax.servlet.jstl>1.2</javax.servlet.jstl>
        <org.springframework.version>4.1.5.RELEASE</org.springframework.version>
        <thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
        <jackson.version>2.5.3</jackson.version>
        <mysql.version>5.1.30</mysql.version>
        <c3p0.version>0.9.1.2</c3p0.version>
        <logback.version>1.1.1</logback.version>
        <slf4j.version>1.7.7</slf4j.version>
        <testng.version>6.8.8</testng.version>
        <commons-lang3.version>3.3.2</commons-lang3.version>
        <mockito.version>1.9.5</mockito.version>
        <cglib.version>2.2.2</cglib.version>
        <guava.version>18.0</guava.version>
        <commons-collections.version>3.2.1</commons-collections.version>
        <commons-validator.version>1.4.1</commons-validator.version>
        <javax.mail.version>1.4.7</javax.mail.version>
        <org.aspectj.version>1.8.6</org.aspectj.version>
        <apache.lucene.version>5.3.0</apache.lucene.version>
    </properties>

  <dependencies>

<!--   JAVAX SERVLET LIB DEPENDENCY -->
    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>jstl</artifactId>
       <version>${javax.servlet.jstl}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${javax.servlet.version}</version>
    </dependency>

        <!--
                SPRING DEPENDENCIES
        -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${org.springframework.version}</version>
      <exclusions>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
      </exclusions>
    </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-expression</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-tx</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>   
        <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
        <version>${thymeleaf.version}</version>
        </dependency>    
        <!--
            JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx)
            Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-oxm</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>
<!--        JACKSON LIB DEPENDENCY FOR JSON SER/DES -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
<!--        MYSQL DB LIB -->
        <dependency>    
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>       
<!-- LogBack dependencies --> 
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>                                    
            <groupId>org.slf4j</groupId>                
            <artifactId>jcl-over-slf4j</artifactId>     
            <version>${slf4j.version}</version>  
        </dependency>               
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>${c3p0.version}</version>
        </dependency>

<!--        COMMONS LIB DEPENDCY -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>${commons-collections.version}</version>
        </dependency>       
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>${commons-validator.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
<!--        GUAVA. We still use it in java 8 for immutable collections -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>           

<!--            TESTING DEPENDENCY -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
        </dependency>   
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>${cglib.version}</version>
        </dependency>
        <dependency>
        <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>${javax.mail.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj.version}</version>
         </dependency>
         <dependency>
             <groupId>org.aspectj</groupId>
             <artifactId>aspectjweaver</artifactId>
             <version>${org.aspectj.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.lucene</groupId>
             <artifactId>lucene-core</artifactId>
             <version>${apache.lucene.version}</version>
         </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>${apache.lucene.version}</version>
        </dependency>        
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queries</artifactId>
            <version>${apache.lucene.version}</version>
        </dependency>
       <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>${apache.lucene.version}</version>
        </dependency>       
<!--         <dependency> -->
<!--            <groupId>org.compass-project</groupId> -->
<!--            <artifactId>compass</artifactId> -->
<!--            <version>2.2.0</version> -->
<!--        </dependency> -->
        <dependency>
          <groupId>com.google.api-client</groupId>
          <artifactId>google-api-client</artifactId>
          <version>1.20.0</version>
          <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>




  <build>
    <finalName>ROOT</finalName>
        <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>2.3.2</version>
               <inherited>true</inherited>
               <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
  </build>
</project>

Any time I do a Maven Update, I need to manually repeat all the steps to fix the Web Deployment Assembly. I've actually had this problem for several months. Any suggestions would be appreciated.

Community
  • 1
  • 1
Alex R
  • 11,364
  • 15
  • 100
  • 180

4 Answers4

8

This kind of problem is solved by:

  • getting the latest version of the Eclipse IDE for Java EE Developers. As of today, this is Eclipse Mars 4.5. Be sure to select the 64 bit version (if your computer is 64 bit) and to install the latest 64 bit JDK (as of today, this is jdk-8u60).
  • correctly setting up the JREs in Eclipse by selecting the installed JDK in the Preferences ("Java > Installed JREs").
  • having up-to-date m2e and m2e-wtp plugins. This is done by going to "Help > Install New Software...", setting this URL for m2e and this URL for m2e-wtp and then installing every proposed software (don't forget to reboot Eclipse after that).
  • correctly setting up the server in Eclipse: in the "Servers" view, right-click and select "New > Server" and then follow the steps for your specific server; in the end, you will need to add your war through the "Add and Remove..." screen.
  • cleaning the project in Eclipse by selecting it and going to "Project > Clean".
  • updating the Maven project by right-clicking the project in Eclipse and going to "Maven > Update Project...".
  • cleaning the server by right-clicking the server and selecting "Clean" (this depends on your server but there's usually a "Clean" option).

I recommend you do all these steps on a fresh Eclipse install to avoid general caching issues.

As a side note, there are several problems with your POM as-is:

  • javax.servlet:javax.servlet-api dependency needs to have the provided scope since this dependency is always provided by the web-server at run-time.
  • javax.servlet:jstl dependency probably doesn't need to have the compile scope and runtime will suffice.
  • You are declaring a lot of Spring dependencies when you don't need to: they will still be included because they already are transitive dependencies of other artifacts. As such, you can remove the declaration of spring-aop, spring-beans, spring-context, spring-expression, spring-tx and spring-web.
  • Your testing dependencies are missing the test scope (testng, mockito-all...)
  • <inherited>true</inherited> is unnecessary in your maven-compiler-plugin declaration as this is the default.

Final POM would be:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ctc.web.proyect</groupId>
    <artifactId>front.web</artifactId>
    <packaging>war</packaging>
    <version>0.2.5</version>
    <name>front.web</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <javax.servlet.jstl>1.2</javax.servlet.jstl>
        <org.springframework.version>4.1.5.RELEASE</org.springframework.version>
        <thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
        <jackson.version>2.5.3</jackson.version>
        <mysql.version>5.1.30</mysql.version>
        <c3p0.version>0.9.1.2</c3p0.version>
        <logback.version>1.1.1</logback.version>
        <slf4j.version>1.7.7</slf4j.version>
        <testng.version>6.8.8</testng.version>
        <commons-lang3.version>3.3.2</commons-lang3.version>
        <mockito.version>1.9.5</mockito.version>
        <cglib.version>2.2.2</cglib.version>
        <guava.version>18.0</guava.version>
        <commons-validator.version>1.4.1</commons-validator.version>
        <javax.mail.version>1.4.7</javax.mail.version>
        <org.aspectj.version>1.8.6</org.aspectj.version>
        <apache.lucene.version>5.3.0</apache.lucene.version>
    </properties>

    <dependencies>

        <!-- JAVAX SERVLET LIB DEPENDENCY -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${javax.servlet.jstl}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- SPRING DEPENDENCIES -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>${thymeleaf.version}</version>
        </dependency>
        <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
            spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- JACKSON LIB DEPENDENCY FOR JSON SER/DES -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <!-- MYSQL DB LIB -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- LogBack dependencies -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>${c3p0.version}</version>
        </dependency>

        <!-- COMMONS LIB DEPENDCY -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>${commons-validator.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- GUAVA. We still use it in java 8 for immutable collections -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>

        <!-- TESTING DEPENDENCY -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>${cglib.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>${javax.mail.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${org.aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>${apache.lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>${apache.lucene.version}</version>
        </dependency>
        <!-- <dependency> -->
        <!-- <groupId>org.compass-project</groupId> -->
        <!-- <artifactId>compass</artifactId> -->
        <!-- <version>2.2.0</version> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.20.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The other consideration you might want to fix is that your groupId and artifactId do not follow Maven conventions: prefer using - as separator instead of ..

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 2
    This was the proverbial answer I didn't want to hear, but it worked. – Alex R Sep 26 '15 at 19:14
  • @AlexR If this is because I am suggesting using the latest Eclipse, don't be afraid. It should work under Luna also and probably you don't need to make a fresh install. Try doing the steps in my answer on your current installation and see if it works (notably installing / updating m2e and m2e-wtp) – Tunaki Sep 26 '15 at 19:32
  • Luna was on my 3rd reinstall already. So I went for the fresh install of Mars and it was smooth. – Alex R Sep 26 '15 at 20:10
  • 2
    Already done all advices of this answer (even basic). With latest plugin version (Neon version). We don't understand why Eclipse does not deploy the same build than Maven do. Its laughing...I have even resources & class tests deployed in `WEB-INF/classes`. Someone else has an idea to fix deployment assembly errors ? thank you – MychaL Apr 03 '17 at 11:41
  • @MychaL Difficult to say without seeing your particular structure, but make sure you install m2e-wtp. There is nothing you should have to do manually (like adding deployment resources; so if you did anything manually, undo it). Those same steps are working fine for me with Neon. – Tunaki Apr 03 '17 at 17:51
  • 3
    It's clearly the problem ... for some people, it works and others not. I have a classic installation with all m2e plugins and m2e-wtp (all updated). Eclipse has become so painful to make its own configuration / execution. – MychaL Apr 04 '17 at 12:45
  • A co-worker has Luna with a similar project and it works perfectly. I take the sources without Eclipse config, I import the Maven project, everything is in error while the Maven build works PERFECTLY. The goal is normally to have a structured project and not dependent on the "developer" computer :( Netbeans has not this problem... – MychaL Apr 04 '17 at 12:49
  • Pb came from Java Build Path and specialy output folder of source folder (check src/test/xxx to not be generated into defaut output) because target/classes is deployed (Eclipse doesn't follow the deployement assembly list only). – MychaL Apr 05 '17 at 14:21
1

your Pom.xml seems to be just fine. However, If you right-click on your project, there should be an option under "maven" to "enable dependency management". That's it. PS: avoid using the maven-eclipse-plugin for the same if you are using m2eclipse. There is absolutely no need for it, it will be confusing, it will generate some mess. Don't use it unless you really know what you are doing.

Hope this helps.

TheLuminor
  • 1,411
  • 3
  • 19
  • 34
  • I didn't find "enable dependency management". I forgot to mention I'm still on Luna, perhaps that's something new in Mars? – Alex R Sep 26 '15 at 13:41
  • I think he's talking about "Enable workspace resolution". It should be on by default anyway. – Tunaki Sep 26 '15 at 13:42
0

Its pretty long list to follow - for me without installing m2e and m2e-wtp, "cleaning the project in Eclipse by selecting it and going to "Project > Clean"." runs maven build with default profile selected.

zhivko
  • 53
  • 1
  • 1
  • 5
0

As I had similar problem the solution was to change the packaging to "war" in pom.xml.

<packaging>war</packaging>
30thh
  • 10,861
  • 6
  • 32
  • 42