问题描述
我遇到了与此类似的问题( java.lang.ClassNotFoundException :org.springframework.web.context.ContextLoaderListener ),区别在于通用修复程序(将Maven依赖项添加到Deployment Assembly中)只是暂时的,每次我执行Maven更新时都会中断,即不太频繁,但足以令人讨厌.
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?
详细信息
这是我得到的错误
我通过以下方法修复它:
And I fix it by going here:
然后在这里:
最后在这里...
在修复后,它的外观如下:
Here's what it looks like once it's fixed:
这是我的pom.xml:
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>
每次执行Maven更新时,我都需要手动重复所有步骤来修复Web部署程序集.实际上,我已经有几个月了这个问题.任何建议,将不胜感激.
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.
推荐答案
此类问题的解决方法是:
This kind of problem is solved by:
- 获取用于Java EE开发人员的Eclipse IDE的最新版本.到目前为止,这是Eclipse Mars 4.5.确保选择64位版本(如果您的计算机是64位版本)并安装最新的64位JDK(从今天开始,这是jdk-8u60).
- 通过在首选项"("Java>已安装的JRE")中选择已安装的JDK,在Eclipse中正确设置JRE.
- 具有最新的
m2e
和m2e-wtp
插件.为此,请转到帮助>安装新软件...",设置此URLm2e
的a>和m2e-wtp
的此URL 每个建议的软件(不要忘记在那之后重新启动Eclipse). - 在Eclipse中正确设置服务器:在服务器"视图中,右键单击并选择新建>服务器",然后按照特定服务器的步骤进行操作;最后,您需要通过添加和删除..."屏幕添加
war
. - 通过选择Eclipse并清除项目,然后转到项目>清理".
- 通过右键单击Eclipse中的项目并转到"Maven>更新项目..."来更新Maven项目.
- 通过右键单击服务器并选择清理"来清理服务器(这取决于您的服务器,但通常有一个清理"选项).
- 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
andm2e-wtp
plugins. This is done by going to "Help > Install New Software...", setting this URL form2e
and this URL form2e-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).
我建议您在全新的Eclipse安装上执行所有这些步骤,以避免常规的缓存问题.
I recommend you do all these steps on a fresh Eclipse install to avoid general caching issues.
请注意,您的POM仍然存在一些问题:
As a side note, there are several problems with your POM as-is:
-
javax.servlet:javax.servlet-api
依赖项必须具有provided
范围,因为此依赖项始终由Web服务器在运行时提供. -
javax.servlet:jstl
依赖项可能不需要具有compile
范围,并且runtime
就足够了. - 您不需要时声明了许多Spring依赖项:它们仍将包括在内,因为它们已经是其他工件的可传递依赖项.这样,您可以删除
spring-aop
,spring-beans
,spring-context
,spring-expression
,spring-tx
和spring-web
的声明. - 您的测试依赖项缺少
test
范围(testng
,mockito-all
...) 您的 -
<inherited>true</inherited>
,因为这是默认.
maven-compiler-plugin
声明中不需要javax.servlet:javax.servlet-api
dependency needs to have theprovided
scope since this dependency is always provided by the web-server at run-time.javax.servlet:jstl
dependency probably doesn't need to have thecompile
scope andruntime
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
andspring-web
. - Your testing dependencies are missing the
test
scope (testng
,mockito-all
...) <inherited>true</inherited>
is unnecessary in yourmaven-compiler-plugin
declaration as this is the default.
最终POM为:
<?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>
您可能要修复的其他注意事项是您的groupId
和artifactId
不遵循Maven约定:首选使用-
作为分隔符,而不是.
.
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 .
.
这篇关于是否有针对Eclipse部署程序集丢失Maven依赖关系的永久修复程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!