Unable to “Run on Server” a webapp from Eclipse

2019-03-08 08:12发布

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

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

15条回答
SAY GOODBYE
2楼-- · 2019-03-08 08:44

Tried everything with no luck. I just had one project in my eclipse. Shut eclipse down, rename the eclipse directory, unzip it again, started fresh in new eclipse. It worked.

No it is not efficient.

查看更多
我只想做你的唯一
3楼-- · 2019-03-08 08:47

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!

查看更多
地球回转人心会变
4楼-- · 2019-03-08 08:50
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
查看更多
Root(大扎)
5楼-- · 2019-03-08 08:51

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:

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.

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

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)

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

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

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

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

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

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

1) Right click your web project

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

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):

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

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

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

4) Press "Finish"

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

Fourth, leave Eclipse than run it again:

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

Fifth, maven reintegration:

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

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")

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

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

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")

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.

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

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?)

查看更多
手持菜刀,她持情操
6楼-- · 2019-03-08 08:52

Steps which I followed and will work 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
查看更多
家丑人穷心不美
7楼-- · 2019-03-08 08:54

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.

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.

  1. Right Button on the project: Project Facets
  2. Check "Utility Module" and save
  3. Remove the application from tomcat and publish it again.
查看更多
登录 后发表回答