EclipseWtp plugin generates inconsistent org.eclipse.wst.common.component files when compared to Eclipse/Maven equivalents


(Heinrich Filter) #1

tl;dr

The org.eclipse.wst.common.component file generated by Gradle’s EclipseWtp plugin is subtly different from the equivalent file when creating a project in Eclipse or when using Maven’s eclipse plugin i.e. the ‘wb-resource’'s ‘source-path’ value does not start with a forward slash.

This causes errors when deploying to WebSphere Liberty Profile (WLP) in Eclipse if WLP is setup to use loose configuration.

I’m willing to implement or help with a fix if this is considered a bug but I first want to hear what you guys are saying.

Objective:

  1. Build a multi-project webapp with Gradle 2. Import project into Eclipse using Gradle EclipseWtp plugin 3. Deploy to WebSphere Liberty Profile (WLP) from Eclipse using loose config i.e. with “Run applications directly from the workplace” enabled.

Problem Symptom: When deploying to WLP in Eclipse (with “Run applications directly from the workspace” enabled) the server cannot find the servlet:

Error 404: javax.servlet.UnavailableException: SRVE0200E: Servlet [pack.MyServlet]: Could not find required class - pack/MyServlet

If the project is deployed as a packaged WAR this error does not occur. Tomcat (or more specifically vFabric tc Server) can deploy the same project even with their “Serve modules without publishing” enabled.

Cause of Problem:

1. Gradle doesn’t generate a org.eclipse.wst.common.component file that is consistent with Eclipse generated or Maven generated metadata.

I.e. the source-path does not start with a leading slash.

Gradle output:

<wb-resource deploy-path="/WEB-INF/classes" source-path="src"/>

Eclipse/Maven output:

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>

2. WebSphere Liberty Profile server is not tolerant enough since Tomcat can deploy the app with loose config?

Example

I created a minimal webapp to illustrate the problem. Even though this is a single-project webapp the same problem would exist in the dependencies. Build instructions can be found in the README

https://github.com/HeinrichFilter/gradle-wlp-example

Workaround?

Gradle makes it difficult/hackish to work around this problem.

For the web project you could use the ‘eclipse.wtp.component.whenMerged’ hook to edit the file.

However in a multi-project build you cannot do that for the dependencies since the wtp config is not available for non-war/non-ear projects.

See: http://issues.gradle.org/browse/GRADLE-2221 http://issues.gradle.org/browse/GRADLE-2186

A comment on one of the tickets recommends the following: 1. Apply the War or Ear plugin 2. Manually add and configure a GenerateEclipseWtpFacet task

Other questions:

Does anyone know if there is a spec for the org.eclipse.wst.common.component file?


(Radim Kubacki) #2

Thanks for your thorough investigation. Yes, we’re interested in bugfixes in this area. If you are going to help us with a fix here are some tips/ideas:

  • make sure that the fix also works for deployment to other servers like Tomcat - add an integration test. most likely it can be added to EclipseWtpModelIntegrationTest class or similar - it might be useful to mention what version of Eclipse/WTP you have tried. this is related to a problem underspecified format of Eclipse metadata files like org.eclipse.wst.common.component. Let us know if find some spec for them.