You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Renaud Pelissier <Re...@infor.com> on 2014/02/11 17:45:30 UTC

How to replace VirtualWebappLoader in Tomcat 8

Hi there !

I saw a post on this already but it doesn't solve my problem.

I have got two directories I want to map to one single web application using the Context file $CATALINA_HOME/conf/Catalina/localhost/Test.xml.
Test1.jsp is making use of Test1.class and Test2.class.

With Tomcat 7 I was successfully using something like this:
<Resources className="org.apache.naming.resources.VirtualDirContext" extraResourcePaths="$MY_HOME\Project1\src , $MY_HOME\Project2\src "      />
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="$MY_HOME\Project1\bin , $MY_HOME\Project2\bin" />

The config below does not work. What am I missing here?
I had to set webAppMount to "/" and internalPath to "/." because if I omit them, I am getting some NullPointerException.

Thanks for your help,

Renaud

----------------------


*         Project1

| src
| src | Test1.jsp
| src | com | company | Test1.class


*         Project2

| src
| src | Test2.jsp
| src | com | company | Test2.class



*         Test.XML

<Context path="/Test" docBase="$MY_HOME \ Project1\src">

<Resources>

<PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\ Project1\src" webAppMount="/" internalPath="/." />
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project2\src"  webAppMount="/" internalPath="/."/>
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project1\bin" webAppMount="/"  internalPath="/."/>
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project2\bin" webAppMount="/"  internalPath="/."/>
</Resources>

</Context>


RE: How to replace VirtualWebappLoader in Tomcat 8

Posted by Renaud Pelissier <Re...@infor.com>.
I finally found some more explanation by myself by digging into Tomcat 8 source code.
In the javadoc of the interface org.apache.catalina.WebResourceRoot everything is very clear (see below):

>	Pre- and Post-Resources may define WEB-INF/lib and WEB-INF/classes in order to make additional libraries and/or classes available to the web application. This mechanism replaces and extends the following features >that were present in earlier versions: 
>	* Aliases - Replaced by Post-Resources with the addition of support for single files as well as directories and JARs. 
>	* VirtualWebappLoader - Replaced by Pre- and Post-Resources mapped to WEB-INF/lib and WEB-INF/classes 
>	* VirtualDirContext - Replaced by Pre- and Post-Resources 
>	* External repositories - Replaced by Pre- and Post-Resources mapped to WEB-INF/lib and WEB-INF/classes 
>	* Resource JARs - Same feature but implemented using the same mechanism as all the other additional resources.


That's exactly the question I was asking! It should definitely be added in the documentation chapter bout Resource.

Regards,

Renaud





-------------------
public interface WebResourceRoot extends Lifecycle

Represents the complete set of resources for a web application. The resources for a web application comprise of multiple ResourceSets and when looking for a Resource, the ResourceSets are processed in the following order: 
	1. Pre - Resources defined by the <PreResource> element in the web application&aposs context.xml. Resources will be searched in the order they were specified. 
	2. Main - The main resources for the web application - i.e. the WAR or the directory containing the expanded WAR 
	3. JARs - Resource JARs as defined by the Servlet specification. JARs will be searched in the order they were added to the ResourceRoot. 
	4. Post - Resources defined by the <PostResource> element in the web application&aposs context.xml. Resources will be searched in the order they were specified. 
The following conventions should be noted: 
	* Write operations (including delete) will only be applied to the main ResourceSet. The write operation will fail if the presence of a Resource in one of the other ResourceSets effectively makes the operation on the main ResourceSet a NO-OP. 
	* A file in a ResourceSet will hide a directory of the same name (and all the contents of that directory) in a ResourceSet that is later in the search order. 
	* Only the main ResourceSet may define a META-INF/context.xml since that file defines the Pre- and Post-Resources. 
	* As per the Servlet specification, any META-INF or WEB-INF directories in a resource JAR will be ignored. 
	* Pre- and Post-Resources may define WEB-INF/lib and WEB-INF/classes in order to make additional libraries and/or classes available to the web application. 
This mechanism replaces and extends the following features that were present in earlier versions: 
	* Aliases - Replaced by Post-Resources with the addition of support for single files as well as directories and JARs. 
	* VirtualWebappLoader - Replaced by Pre- and Post-Resources mapped to WEB-INF/lib and WEB-INF/classes 
	* VirtualDirContext - Replaced by Pre- and Post-Resources 
	* External repositories - Replaced by Pre- and Post-Resources mapped to WEB-INF/lib and WEB-INF/classes 
	* Resource JARs - Same feature but implemented using the same mechanism as all the other additional resources. 
------------------------


Renaud 

-----Message d'origine-----
De : Mark Thomas [mailto:markt@apache.org] 
Envoyé : mardi 11 février 2014 20:09
À : Tomcat Users List
Objet : Re: How to replace VirtualWebappLoader in Tomcat 8

On 11/02/2014 17:31, Renaud Pelissier wrote:
> Okay, I had it working finally by setting webAppMount to  "/WEB-INF/classes" for every classes directory.
> So I understand the /WEB-INF/classes mount point is hard coded into the default Loader? Is it different to use /WEB-INF/lib?

/WEB-INF/classes is for classes
/WEB-INF/lib is for JARs

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to replace VirtualWebappLoader in Tomcat 8

Posted by Mark Thomas <ma...@apache.org>.
On 11/02/2014 17:31, Renaud Pelissier wrote:
> Okay, I had it working finally by setting webAppMount to  "/WEB-INF/classes" for every classes directory.
> So I understand the /WEB-INF/classes mount point is hard coded into the default Loader? Is it different to use /WEB-INF/lib?

/WEB-INF/classes is for classes
/WEB-INF/lib is for JARs

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to replace VirtualWebappLoader in Tomcat 8

Posted by Renaud Pelissier <Re...@infor.com>.
Okay, I had it working finally by setting webAppMount to  "/WEB-INF/classes" for every classes directory.
So I understand the /WEB-INF/classes mount point is hard coded into the default Loader? Is it different to use /WEB-INF/lib?

Regards,

Renaud

------------------------


*         Test.XML
<Context path="/Test" docBase="$MY_HOME\TotoTest\src">

<Resources>
	<PreResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\TotoTest\bin\" webAppMount="/WEB-INF/classes" />
	<PreResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\TotoTest2\bin\" webAppMount="/WEB-INF/classes" />
	<PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\TotoTest\src\" webAppMount="/" />
	<PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\TotoTest2\src\"  webAppMount="/" />
</Resources>

</Context>


-----Message d'origine-----
De : Renaud Pelissier [mailto:Renaud.Pelissier@infor.com] 
Envoyé : mardi 11 février 2014 17:46
À : users@tomcat.apache.org
Objet : How to replace VirtualWebappLoader in Tomcat 8

Hi there !

I saw a post on this already but it doesn't solve my problem.

I have got two directories I want to map to one single web application using the Context file $CATALINA_HOME/conf/Catalina/localhost/Test.xml.
Test1.jsp is making use of Test1.class and Test2.class.

With Tomcat 7 I was successfully using something like this:
<Resources className="org.apache.naming.resources.VirtualDirContext" extraResourcePaths="$MY_HOME\Project1\src , $MY_HOME\Project2\src "      />
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="$MY_HOME\Project1\bin , $MY_HOME\Project2\bin" />

The config below does not work. What am I missing here?
I had to set webAppMount to "/" and internalPath to "/." because if I omit them, I am getting some NullPointerException.

Thanks for your help,

Renaud

----------------------


*         Project1

| src
| src | Test1.jsp
| src | com | company | Test1.class


*         Project2

| src
| src | Test2.jsp
| src | com | company | Test2.class



*         Test.XML

<Context path="/Test" docBase="$MY_HOME \ Project1\src">

<Resources>

<PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME\ Project1\src" webAppMount="/" internalPath="/." />
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project2\src"  webAppMount="/" internalPath="/."/>
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project1\bin" webAppMount="/"  internalPath="/."/>
                <PostResources className="org.apache.catalina.webresources.DirResourceSet" base="$MY_HOME \ Project2\bin" webAppMount="/"  internalPath="/."/> </Resources>

</Context>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org