无法从 Eclipse“在服务器上运行”一个 web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6703988/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:18:15  来源:igfitidea点击:

Unable to "Run on Server" a webapp from Eclipse

eclipsetomcat6eclipse-wtp

提问by Ram

When running my WebApp project from Eclipse most of times it run correctly. But if by mistake to stop server, I kill it in "Console" view on instead of "Stop" Server from "Servers" View. While running clean project I get this

从 Eclipse 运行我的 WebApp 项目时,大多数情况下它都能正确运行。但是如果错误地停止服务器,我会在“控制台”视图中杀死它,而不是从“服务器”视图中的“停止”服务器。在运行干净的项目时,我得到了这个

java.lang.NullPointerException
at org.eclipse.wst.common.componentcore.internal.util.VirtualReferenceUtilities.getDefaultProjectArchiveName(VirtualReferenceUtilities.java:81)
at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getJavaClasspathReferences(J2EEModuleVirtualComponent.java:332)
at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getNonManifestRefs(J2EEModuleVirtualComponent.java:236)
at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:160)
at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:208)
at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:201)
at org.eclipse.jst.common.internal.modulecore.SingleRootUtil.hasConsumableReferences(SingleRootUtil.java:217)
at org.eclipse.jst.common.internal.modulecore.SingleRootUtil.validateSingleRoot(SingleRootUtil.java:165)
at org.eclipse.jst.common.internal.modulecore.SingleRootUtil.isSingleRoot(SingleRootUtil.java:93)
at org.eclipse.jst.common.internal.modulecore.SingleRootExportParticipant.canOptimize(SingleRootExportParticipant.java:84)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.canOptimize(FlatVirtualComponent.java:136)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.cacheResources(FlatVirtualComponent.java:118)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.fetchResources(FlatVirtualComponent.java:101)
at org.eclipse.wst.web.internal.deployables.FlatComponentDeployable.members(FlatComponentDeployable.java:147)
at org.eclipse.wst.server.core.internal.ModulePublishInfo.hasDelta(ModulePublishInfo.java:418)
at org.eclipse.wst.server.core.internal.ServerPublishInfo.hasDelta(ServerPublishInfo.java:443)
at org.eclipse.wst.server.core.internal.Server.hasPublishedResourceDelta(Server.java:1539)
at org.eclipse.wst.server.core.internal.Server$ResourceChangeJob.visit(Server.java:214)
at org.eclipse.wst.server.core.internal.Server.visitModule(Server.java:2929)
at org.eclipse.wst.server.core.internal.Server.visit(Server.java:2913)
at org.eclipse.wst.server.core.internal.Server$ResourceChangeJob.run(Server.java:225)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

And while launching I get this

在启动时我得到了这个

SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Webapp does not exist or is not a readable directory
    at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4319)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

Please help recover from this.

请帮助从中恢复。

采纳答案by Ram

I have stopped using this method of running my webapp. I use mvn tomcat:runinstead. Much easier. Though I don't know how to debug.

我已经停止使用这种运行我的 web 应用程序的方法。我用mvn tomcat:run代替。容易多了。虽然我不知道如何调试。

回答by Alejo Ceballos

I had a hard time to make it work, but thanks to "Alexander Pogrebnyak" (see deploying a war file in WTP(Eclipse) tomcat server) I was able to make Eclipse Web Projects work with Maven through m2e:

我很难让它工作,但多亏了“Alexander Pogrebnyak”(参见在 WTP(Eclipse) tomcat 服务器中部署 war 文件),我能够通过 m2e 使 Eclipse Web 项目与 Maven 一起工作:

Before starting, I must say that I'm a very suspicious man, so I always start by cleaning all my projects using "Eclipse > Project > Clean..." menu (without "start a build immediately" option checked). I also do not have "Eclipse > Project > Build Automatically" option checked.

在开始之前,我必须说我是一个非常可疑的人,所以我总是从使用“Eclipse > 项目 > 清理...”菜单(没有选中“立即开始构建”选项)清理我的所有项目开始。我也没有选中“Eclipse > Project > Build Automatically”选项。

By the way, I suppose that you will have your m2e plugin installed already, or what I'm going to state has no meaning...

顺便说一句,我想你已经安装了你的 m2e 插件,或者我要声明的内容没有意义......

Well, let's start:

好吧,让我们开始吧:

First, bye bye Server configuration:

一、再见服务器配置:

1) If your have any project in a previous server configuration, remove it (right click on the server and select "Add and remove" option)

1)如果您在以前的服务器配置中有任何项目,请将其删除(右键单击服务器并选择“添加和删除”选项)

2) Clean your server work directory (right click on the server and select "Tomcat Server Work Directory")

2)清理你的服务器工作目录(右键单击服务器并选择“Tomcat服务器工作目录”)

3) Clean the compiled "leftovers" (right click on the server and select "Clean")

3)清理编译好的“剩菜”(右键服务器,选择“清理”)

4) Remove your server configuration from the "Servers" tab

4)从“服务器”选项卡中删除您的服务器配置

5) Completely delete your "Servers" project/folder (shown in your "Project Explorer" tab)

5)完全删除您的“服务器”项目/文件夹(显示在您的“项目资源管理器”选项卡中)

6) BONUS: I also remove my server runtime environment ("Eclipse > Window > Preferences > Server > Runtime Environments")

6)奖励:我还删除了我的服务器运行时环境(“Eclipse > Window > Preferences > Server > Runtime Environments”)

Second, "Maven clean" (if your web project has a "Maven nature"):

其次,“Maven clean”(如果您的网络项目具有“Maven 性质”):

1) Right click your web project

1)右键单击您的Web项目

2) "Pop up Menu > Run As > Maven clean"

2)“弹出菜单>运行方式>Maven清理”

This should wipe out your target folder

这应该会清除您的目标文件夹

Third, Instal m2e WTP integration (yeah! It does not come as "default". One whole day to figure it out):

第三,安装 m2e WTP 集成(是的!它不是“默认”。一整天来弄清楚):

1) Open Maven "Discovery" option (Eclipse > Windows > Preferences > Maven > Discovery)

1)打开Maven“发现”选项(Eclipse > Windows > Preferences > Maven > Discovery)

2) Press "Open Catalog" Button (a "m2e Marketplace" window should appear)

2)按“打开目录”按钮(应出现“m2e Marketplace”窗口)

3) Scroll down until you find the "WTP Integration" option, then "check" it!

3) 向下滚动直到找到“WTP 集成”选项,然后“检查”它!

4) Press "Finish"

4)按“完成”

5) A "plugin screen like" will appear. "Next", "Next", "Agree", blah, blah, blah...

5) 将出现一个“插件屏幕”。“下一个”,“下一个”,“同意”,等等,等等,等等……

Fourth, leave Eclipse than run it again:

第四,离开 Eclipse 再运行一次:

1) If not asked to restar Eclipse (that I find hard to believe you won't), restart it yourself!

1)如果没有要求重新启动 Eclipse(我很难相信你不会),请自己重新启动它!

Fifth, maven reintegration:

五、maven重新整合:

1) Add Maven nature to the project (Right click your web project, "Pop up Menu > Configure > Convert to Maven Project")

1) 将 Maven 性质添加到项目中(右键单击您的 Web 项目,“弹出菜单 > 配置 > 转换为 Maven 项目”)

2) Update your maven configuration (Yeah, yeah, suspicious, I know). Right click your web project again, now with a "M" on its icon ("Pop up Menu > Maven > Update Project")

2)更新你的maven配置(是的,是的,可疑,我知道)。再次右键单击您的 Web 项目,现在其图标上带有“M”(“弹出菜单 > Maven > 更新项目”)

3) Run a maven install (Right click your web project, "Pop up Menu > Run As > Maven install")

3) 运行 Maven 安装(右键单击您的 Web 项目,“弹出菜单 > 运行方式 > Maven 安装”)

4) Build your project ("Eclipse > Project > Build All")

4) 构建您的项目(“Eclipse > 项目 > 全部构建”)

Sixth, put it all to work:

六、全力以赴:

1) Deploy and run your web application (Right click your web project, "Pop up Menu > Run As > Run on Server")

1) 部署并运行您的 Web 应用程序(右键单击您的 Web 项目,“弹出菜单 > 运行方式 > 在服务器上运行”)

2) You will be asked to create another server configuration. It will create the "Servers" project/folder again, but that's the way it is.

2) 您将被要求创建另一个服务器配置。它将再次创建“服务器”项目/文件夹,但事实就是如此。

That's it!!! I gotta admit, once I ran the server, it didn't work, but this time (i dunnot know why) "Log4J" libraries could not be found. After one "project clean" + "maven clean" and one "maven install" + "project build" another message stating that my Servlet class could not be found. Once again, I executed a "project clean" + "maven clean" and a "maven install" + "project build" and "voila"!!! It worked (And that's why I'm so suspicious).

就是这样!!!我得承认,一旦我运行了服务器,它就不起作用了,但是这次(我不知道为什么)找不到“Log4J”库。在一个“项目清理”+“maven 清理”和一个“maven 安装”+“项目构建”之后,另一条消息指出我的 Servlet 类无法找到。再一次,我执行了“项目清理”+“maven 清理”和“maven 安装”+“项目构建”和“瞧”!!!它有效(这就是我如此怀疑的原因)。

I was starting to get worried with this new Juno + m2e double... Never had this kind of problem with Indigo or Ganymede... But I guess I can trust Eclipse again (can I?)

我开始担心这个新的 Juno + m2e double ...... Indigo 或 Ganymede 从来没有遇到过这种问题......但我想我可以再次信任 Eclipse(我可以吗?)

回答by user1995400

Dont do those crazy cosmic workarounds !!

不要做那些疯狂的宇宙变通方法!!

This works fine:

这工作正常:

Add to your ".project" file (hidden) these lines:

将这些行添加到您的“.project”文件(隐藏)中:

 <natures>
    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
    <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.eclipse.m2e.core.maven2Nature</nature>
    <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
  </natures>

Enjoy !

享受 !

Why? if you check that unexisting directory, well, that "../.metadata/blah/blah/tmp0/wtpwebapps/YOURPROJECT/"is EMPTY: then your build aint creating the WAR... !!! Because maven plugin isnt understanding HE HAVE TO !

为什么?如果你检查那个不存在的目录,嗯,那"../.metadata/blah/blah/tmp0/wtpwebapps/YOURPROJECT/"是 EMPTY:那么你的构建不会创建 WAR ...... !!! 因为 maven 插件不理解他必须!

I found this after comparing two .project files from both different deploying/non-deploying projects...

我在比较了来自不同部署/非部署项目的两个 .project 文件后发现了这一点......

Hope helped !

希望有所帮助!

回答by Олег Всильдеревьев

I have deleted the "problem folder" .metadata.plugins\org.eclipse.wst.server.core\tmp0\ and it works now :)

我已经删除了“问题文件夹”.metadata.plugins\org.eclipse.wst.server.core\ tmp0\,现在可以使用了:)

回答by Bob Yang

I have the exact same problem and exact exception, but I solved the problem just by specify package type of POM to war like "war" and right click the project and select 'Maven > Update Project Configuration', then re-deploy that web module to tomcat server, that's it!

我有完全相同的问题和完全异常,但我只是通过指定 POM 的包类型来解决这个问题,如“war”并右键单击项目并选择“Maven > 更新项目配置”,然后重新部署该 Web 模块到tomcat服务器,就是这样!

回答by Halu Kim

I suffered from this problem, but cause was different. Problem sprang from wrong server name([Project Name] != [Server Name]). I thought that i could figure out by recreate Server.

我遇到了这个问题,但原因不同。问题源自wrong server name([Project Name] != [Server Name]). 我以为我可以通过重新创建 Server来弄清楚。

This Problem can solve by following below steps:

这个问题可以通过以下步骤解决:

  1. Remove Server : right click on [Severs]and remove server.
  2. Delete Server : right click on [Project Explorer]and delete Server(you created).
  3. Clean Project : menu[Project -> Clean]
  4. Create Server : right click on [Severs]and new server.
  5. Edit server.xml : Edit server.xmlfoor your web server.
  6. Add Server : right click on [Severs]and remove server.
  1. 删除服务器:右键单击[Severs]并删除服务器。
  2. 删除服务器:右键单击[Project Explorer]并删除服务器(您创建的)。
  3. 清洁项目:菜单[Project -> Clean]
  4. 创建服务器:右键单击[Severs]和新服务器。
  5. 编辑 server.xml :编辑server.xml您的 Web 服务器。
  6. 添加服务器:右键单击[Severs]并删除服务器。

回答by arviarya

Just do maven -> Update project configuration and clean/build from your eclipse. Project will be loaded.

只需执行 maven -> 更新项目配置并从 Eclipse 中清理/构建即可。项目将被加载。

回答by Luis Diaz

I was quite puzzled by the problem because I had another jar dependency working before the issue occurred. I am using Eclipse Luna which already had m2e integration and none of the above solutions worked for me.

我对这个问题感到非常困惑,因为在问题发生之前我有另一个 jar 依赖项在工作。我正在使用 Eclipse Luna,它已经有 m2e 集成,但上述解决方案都不适合我。

The problem started when adding a new jar dependency to a maven war project, but it still worked well when that one was commented out in the pom. Luckily I was able to compare both projects and eventually the issue was related to a missing project facet in the new jar project: Utility Module.

问题是在向 Maven War项目添加新的 jar 依赖项时开始的,但是当在 pom.xml 中注释掉该依赖项时它仍然运行良好。幸运的是,我能够比较两个项目,最终问题与新 jar 项目中缺少的项目方面有关:Utility Module。

  1. Right Button on the project: Project Facets
  2. Check "Utility Module" and save
  3. Remove the application from tomcat and publish it again.
  1. 项目上的右键:Project Facets
  2. 勾选“实用模块”并保存
  3. 从 tomcat 中删除应用程序并再次发布它。

回答by Cynthia Elliot

Check this version:

<web-app version="**2.5**" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_**2_5**.xsd" metadata-complete="true">

and 

org.eclipse.wst.common.project.facet.core.xml

<installed facet="jst.web" version="**2.5**"/>

It can be incompatible with the chosen server. In my case when I tried to upgrade 3.0 tomcat 6.0 stopped working so I had to revert back to 2.5


so upgrade your server to a highter version or downgrade the web.xml version and run maven --> update project and try again

回答by SkorpEN

In my case it was enough to copy (from working project):

在我的情况下,复制(从工作项目)就足够了:

  1. .settings
  2. .classpath
  3. .projects
  1. .设置
  2. .classpath
  3. .projects

回答by Sahil

Steps which I followed and will work 100%:

我遵循并将100%工作的步骤:

  1. Clean your server and your server working directory by right clicking on the server
  2. Delete the server folder from your project explorer window
  3. Remove server from the runtime environment ie from Eclipse -> Window -> Preferences -> Server -> Runtime Environments
  4. Shut eclipse and start again
  5. Run the file on server again reconfigure the Apache server
  6. Problem is solved
  1. 通过右键单击服务器来清理服务器和服务器工作目录
  2. 从项目资源管理器窗口中删除服务器文件夹
  3. 从运行时环境中删除服务器,即从 Eclipse -> Window -> Preferences -> Server -> Runtime Environments
  4. 关闭eclipse并重新开始
  5. 再次在服务器上运行文件重新配置Apache服务器
  6. 问题解决了