Is there a permanent fix for building an Eclipse deployment that is losing Maven dependency?

I had a problem like this one ( java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener ), the difference in my case is that the Normal fix (adding Maven dependencies to the deployment assembly) is only temporary, and it is is interrupted every time I do a Maven update, which is not too often, but enough to be a real nuisance.

Is there a permanent fix?

DESCRIPTION

This is the error I get enter image description here

And I will fix this 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: 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 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> 

Anytime I do a Maven update, I need to manually repeat all the steps to fix the web deployment build. I had this problem for several months. Any suggestions would be appreciated.

+6
source share
3 answers

This problem is solved by:

  • Get the latest version of the Eclipse IDE for Java EE Developers . Today it is Eclipse Mars 4.5. Be sure to select the 64-bit version (if your computer is 64 bit) and install the latest 64-bit JDK (today it is jdk-8u60).
  • proper JRE configuration in Eclipse by selecting the installed JDK in the settings ("Java> Installed JREs").
  • with updated m2e and m2e-wtp . This is done by going to "Help> Install New Software ...", setting this URL for m2e and this URL for m2e-wtp , and then installing each proposed software (remember to restart Eclipse after that).
  • proper server configuration 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.
  • Clean up a project in Eclipse by selecting it and choosing Project> Clean.
  • updating the Maven project by right-clicking the project in Eclipse and choosing "Maven> Update Project ...".
  • cleaning the server by right-clicking on the server and selecting โ€œCleanโ€ (this depends on your server, but usually there is the โ€œClearโ€ option).

I recommend that you complete all these steps in a new Eclipse installation to avoid common caching issues.

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

  • javax.servlet:javax.servlet-api The dependency must have a scope provided , since this dependency is always provided by the web server at run time.
  • javax.servlet:jstl dependencies probably don't need to have a compile and runtime scope.
  • You declare many Spring dependencies when you don't need to: they will be included anyway, since they are already transitive dependencies of other artifacts. That way you can remove the declaration of spring-aop , spring-beans , spring-context , spring-expression , spring-tx and spring-web .
  • Your test dependencies lack the test scope ( testng , mockito-all ...)
  • <inherited>true</inherited> not required in the maven-compiler-plugin declaration, as this is the default .

The final POM will 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 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> 

Another consideration you can fix is โ€‹โ€‹that your groupId and artifactId do not comply with Maven conventions: prefer to use - as a separator instead . .

+6
source

your Pom.xml looks just fine. However, if you right-click on your project, the "maven" section should have the option "enable dependency management". It. PS : do not use maven-eclipse-plugin for the same if you use m2eclipse. There is no need for this, it will be confused, it will create a mess. Do not use it unless you really know what you are doing.

Hope this helps.

+1
source

Its a rather long list - for me, without installing m2e and m2e-wtp, "clean up the project in Eclipse, select it and go to" Project> Clean. "Starts the maven collection with the default profile selected.

0
source

All Articles