Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a permanent fix for Eclipse Deployment Assembly losing the Maven Dependencies?

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.

like image 840
Alex R Avatar asked Jul 18 '15 20:07

Alex R


1 Answers

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 ..

like image 69
Tunaki Avatar answered Sep 21 '22 18:09

Tunaki