Eclipse Maven Web 应用程序 - 无法再在服务器上运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2641379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse Maven web application - can not run on server anymore
提问by wuntee
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.
我有一个 maven eclipse webapp 项目,我可以右键单击它并“在服务器上运行”,它将部署在 tomcat 上。我最近做了一个“maven -> 更新项目配置”,现在我不能将项目作为 web 应用程序部署和运行。有没有人见过这个?tomcat 的唯一输出如下 - 它甚至看起来不像是在尝试部署应用程序。
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:
POM 仍然设置为 WAR,但在清理项目后,我现在为作为 Maven 依赖项包含的库获取 ClassNotFoundExceptions:
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:
这是我的 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>
回答by ahmad
I found the answer on
我找到了答案
Tomcat 和 Spring Web - 找不到类异常 org.springframework.web.context.ContextLoaderListener
you need to push Maven dependencies to the server when the project is published to it.
当项目发布到服务器时,您需要将 Maven 依赖项推送到服务器。
Right Click on your web project in Project Explorer -> select 'Properties'. Under project properties, select 'Deployment Assembly'.
在 Project Explorer 中右键单击您的 Web 项目 -> 选择“属性”。在项目属性下,选择“部署程序集”。
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.
Deployment Assembly 属性页面显示了将由 Eclipse 作为组装工件发布到服务器的内容。您需要告诉 Eclipse 您也希望发布所有 Maven 依赖项。
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
为此,请单击“添加”按钮,然后选择“Java 构建路径条目”。单击下一步并选择 Maven 依赖项。当 Eclipse 将您的项目发布到 WST 服务器时,这会将 Maven 依赖 JAR 文件发布到 lib 文件夹
回答by Andy Chapman
Three possible solutions. I've used all three depending on how it went wrong.
三种可能的解决方案。我已经使用了所有三个取决于它是如何出错的。
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.
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.
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).
我通过从我的 POM 中删除 spring 安全依赖项来解决这个问题(我只有 spring-security-taglibs 和 spring-security-config 拉入我需要的所有其他内容),保存了 POM,让 Maven 做它的事情,然后将它们添加回来再次,让Maven再次获取依赖,并在Eclipse中重启服务器。出现问题时,Eclipse 项目中的Maven 依赖目录似乎缺少spring-security-web 工件(其中包含org.springframework.security.web.session.HttpSessionEventPublisher)。对我来说,它只会在我重新启动 PC 后启动 Eclipse 时发生,所以我假设它是 Windows (Vista) 并且 Eclipse M2Eclipse 插件在文件锁定或其他方面不能很好地播放。
替代解决方案(问题再次发生,以前的解决方案不起作用)。这一次,我从我本地的 maven 存储库中删除了 org/springframework 目录(Eclipse Window->Preferences->Maven->User Settings 中的那个)。然后,更新 Maven 依赖项,哇,我们又来了。
如果您已完成“Maven->更新项目配置”并且发生这种情况,很可能是因为您的“部署程序集”设置不包括 Maven 依赖项。转到项目-> 属性-> 部署程序集。检查 Maven Dependencies 是否在那里,并且有 /WEB-INF/lib 的部署路径。如果没有,请单击添加并在 Java 构建路径选项下找到它。如果它不存在,则您的构建路径也可能已损坏(尽管我从未发生过这种情况)。
回答by Pascal Thivent
Maybe you changed the <packaging>
from war
to something else per accident. Can you show your POM?
也许您每次事故都将<packaging>
from更改war
为其他内容。你能展示你的POM吗?
Can you also confirm that you have the Maven WTP Integration for WTPinstalled (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 )?
您能否还确认您安装了WTP的Maven WTP 集成(这是不可能的,但也许您安装了最新版本的 M2Eclipse 没有这个额外的东西,并且在您更新项目配置之前一切正常)?
回答by Asaf Mesika
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.
我在 WAR 项目中遇到了奇怪的编译错误。由于某种原因,类路径发生了某种变化,它忽略了我工作区中 WAR 所依赖的其他项目。
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.
最终有效的唯一解决方案是擦除我的工作区,并在每个项目中删除 .classpath、.project 和 .settings。从一个新的工作区开始解决了它。
I did find a bugmentioning something similar to this in Maven WTP bug tracker, but I didn't get enough votes to get fixed I guess.
我没有找到一个错误提的Maven的WTP bug跟踪系统类似这样的东西,但我没有得到足够的票数得到固定,我猜。
回答by blank
Under project properties, go to "facets", press convert to something something, enable dynamic web module and press apply.
在项目属性下,转到“facets”,按转换为某物,启用动态 Web 模块并按应用。
回答by wuntee
None of these helped - I ended up just disabling workspace resolution, and dealing with installing the workspace dependancies when they were out of date.
这些都没有帮助 - 我最终只是禁用了工作区解析,并在它们过时时处理安装工作区依赖项。
回答by Andy Chapman
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.
这一次,我从我本地的 maven 存储库中删除了 org/springframework 目录(Eclipse Window->Preferences->Maven->User Settings 中的那个)。然后,更新 Maven 依赖项,哇,我们又来了。
回答by Lars
I had the same problem today, for me it helps to reinstall apache in eclipse an rebuilding/refreshing the project afterwards
我今天遇到了同样的问题,对我来说它有助于在 Eclipse 中重新安装 apache 之后重建/刷新项目
回答by Noremac
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.
今天我发现在项目上运行 maven clean 后它又开始工作了(例如,从命令行运行 mvn clean)。试一试,看看它是否适合你。
This is NOT equivalent to the eclipse clean as it only deletes a selected few folders from the target directory, not the whole thing.
这不等同于 eclipse clean,因为它只从目标目录中删除选定的几个文件夹,而不是整个文件夹。
回答by Dave B
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
- 右键单击项目 -> Maven -> 更新项目...
- Eclipse Servers 选项卡:停止服务器,右键单击 Tomcat v# -> Clean... -> OK
Here are the troubleshooting steps I use to see what Eclipse is actually deployingwhen 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...")
以下是我用来查看 Eclipse在运行 tomcat 时实际部署的故障排除步骤。这是目前的火星和霓虹灯。(这些步骤假设您已经使用“在服务器上运行...”至少运行了一次项目)
- Pull up the settings for running your project on tomcat:
Right click project -> Run As -> Run Configurations... - 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
- 调出在 tomcat 上运行项目的设置:
右键单击项目 -> Run As -> Run Configurations... - 转到参数选项卡并查看 VM 参数,您将看到如下内容:
查找
-Dwtp.deploy
. 对我来说是
D:\code\workspaceNeon\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
D:\code\workspaceNeon\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
- 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 - Be sure to exit out of that directory when you are done, otherwise eclipse will get errors trying to modify/update it
- 该目录包含标准的 webapp 部署结构。在您的操作系统文件资源管理器中打开该目录并检查内容。当我查看 my 时
WEB-INF/lib
,我发现我的大部分依赖项都丢失了 - 完成后一定要退出该目录,否则 eclipse 会在尝试修改/更新它时出错
Now it's time to fix the problem. Let's see what Eclipse is supposedto be deploying:
现在是时候解决这个问题了。让我们看看 Eclipse应该部署什么:
Open the Deployment Assembly settings for your project:
Right click project -> Properties -> Deployment Assembly
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...
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
- 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"
打开项目的部署程序集设置:
Maven 依赖项是上面的关键项目。如果缺少,请关闭对话框并进行 Maven 更新:右键单击项目 -> Maven -> 更新项目...
现在我们已经进行了更新,让我们手动清除服务器工作目录并重新发布。这可能并不总是必要的,但它是确保所有内容在部署程序集中显示的内容与实际部署的内容之间同步的好方法:
Good luck!
祝你好运!