Unable to “Run on Server” a webapp from Eclipse

2019-03-08 08:43发布

问题:

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.

回答1:

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



回答2:

Dont do those crazy cosmic workarounds !!

This works fine:

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

 <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 !

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

Hope helped !



回答3:

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



回答4:

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!



回答5:

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



回答6:

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.

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.xml foor your web server.
  6. Add Server : right click on [Severs] and remove server.


回答7:

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.


回答8:

Check Tomcat doc for Document base xyz does not exist or is not a readable directory:

Document base does not exist or is not a readable directory The URL specified by the war parameter must identify a directory on this server that contains the "unpacked" version of a web application, or the absolute URL of a web application archive (WAR) file that contains this application. Correct the value specified by the war parameter.

Can you manually do "Clean..." and then "Publish" (from context menu on Tomcat in Servers view) after clean project is completed?



回答9:

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



回答10:

This problem might be caused by your local project being out of sync with your code repository. I would suggest to refresh/synchronize your project.



回答11:

I encountered the same issue and cleaning and recreating server does not help. But when I deployed another project, it was able to start successfully. After much comparison, I found differences in the .project files. So I copy the contents of the .project file of the working project into the one that has problem, add it back to the server and it works. Following is the contents of the .project file that works. Note that you need to change the name of the project accordingly:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Project Name</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
    <buildCommand>
        <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.common.project.facet.core.builder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.validation.validationbuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
    <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
    <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>



回答12:

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.



回答13:

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


回答14:

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


回答15:

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

  1. .settings
  2. .classpath
  3. .projects