0

In my development team, we have framework and business developers.

The framework is a JEE6 webapp already, and business developers uses the framework to build their web pages via web interface provided by the framework and to intermediate the calls to business services.

Each business application is built as a external JAR file which is added to the tomcat start classpath. Also, they are "Web Fragment Projects" (WFP) in eclipse, because it is also possible to add custom JSP, HTML, CSS whatever and also some of them use web-fragment.xml.

So far, so good, everything is working fine outside eclipse...

In eclipse, using the WFP and the framework as a "Dynamic Web Project" (DWP) everything is fine again ...

But for business developers I would like to create Tomcat Server in eclipse and pointing it to the WAR directly and make it deploy the WFP together.

I did several attempts adding WFP to classpath in .launch file, I also tried to add bin dir in tomcat "VirtualWebappLoader", but there's no way the web-fragment.xml gets read.

Any clue in how to achieve it???

Ps: running tomcat outside eclipse and debug the WFP remotely is not an option.

Reginaldo Santos
  • 840
  • 11
  • 24

1 Answers1

2

This is an old thread and it it seems I'm the only one with this scenario, but still, I would like to share the answer.

  1. The WFPs are now Maven projects and the build output goes to /target/classes.

  2. There is a normal wtp-tools web container (tomcat) pointing to a WAR file in file system.

  3. Solution: I've kept with VirtualWebappLoader and added a new flag for JarScanner as shown below:

    <!-- List of Apps Jars -->
    <Loader
    className="org.apache.catalina.loader.VirtualWebappLoader"
    virtualClasspath="apptest/target/classes;
    customtest/target/classes"/>

    <!--
    Treat directory as expanded jar.
    For details: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Virtual_webapp
    -->
    <JarScanner scanAllDirectories="true" />

UPDATE

The ones using Tomcat 8 will notice the VirtualWebappLoader is no longer there. So take a look at Resources. It has been replaced by Pre, Jar and Post resources.

However, I didn't find a proper way to load an exploded Jar with META-INF/resources and META-INF/web-fragment.xml to WEB-INF/lib as required for Servlet 3.0 spec.

When using the proposed examples from Tomcat documentation and mapping exploded Jar directory to WEB-INF/classes everything seems to be 'OK', but META-INF/resources and web-fragment.xml declared elements are not available:

<Resources>
  <PreResources
    className="org.apache.catalina.webresources.DirResourceSet"
    base="/home/reginaldosantos/apptest/target/classes"
    webAppMount="/WEB-INF/classes"
  /> 
</Resources>

Then, changing webAppMount to "/WEB-INF/lib" give me some ClassNotFoundException in startup.

In the end, after several attempts I came up with a workaround:

<Resources>
  <PreResources
    className="org.apache.catalina.webresources.DirResourceSet"
    base="/home/reginaldosantos/apptest/target/classes"
    webAppMount="/WEB-INF/classes"
  />
  <JarResources
    className="org.apache.catalina.webresources.DirResourceSet" 
    base="/home/reginaldosantos/apptest/target/classes/META-INF/resources"
    webAppMount="/"
  /> 
</Resources>

Not too sure about that though.

Hope it helps some one ;-)

Reginaldo Santos
  • 840
  • 11
  • 24
  • 1
    Do you know how the same configuration can be migrated to Tomcat 8?They removed the VirtualWebappLoader. – matteosilv Jun 12 '17 at 14:53
  • @matteosilv yes, definetly! Take a look on [Tomcat 8 - Resources](https://tomcat.apache.org/tomcat-8.5-doc/config/resources.html). It has been replaced by Pre and Post resources: ` ` – Reginaldo Santos Jun 13 '17 at 19:04
  • Thank you. are you sure that an eventuali web-fragment.xml is deployed that way? – matteosilv Jun 20 '17 at 22:11
  • I'm sorry @matteosilv. Initially I just answered how to replace VirtualWebappLoader. Indeed, it was difficult to build some equivalent configuration for this uncommon scenario. Hope you fine with the answer now. Maybe, for "WFPs" the best is to ensure they are a dependency of the web project and then they will be available at WEB-INF/lib without any hack at all. – Reginaldo Santos Jun 21 '17 at 16:15