You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bob DeRemer <bo...@thingworx.com> on 2011/06/30 17:17:24 UTC

how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

We're running tomcat 6.0.32 64-bit on Windows Server 2008 R2.  We have a requirement to support pluggable extensions to our webapp.  We do not want the associated JAR(s) in the WEB-INF/lib directory.  Instead, we want to place them in a WEB-INF/lib/extensions folder that we created.

To do this, I need to inform my webapp class loader about the extra repository.  From looking at VirtualWebappLoader, this looks like just what I need.

Problem is - I can't seem to get this to work.  I have created a context.xml file and placed it in our META-INF folder.  The contents are:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
   <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
</Context>

>From reading the tomcat documentation, it seems like Tomcat should automatically detect the context.xml file and add the classloader, but it doesn't seem to be looking in this extra directory.  I've tried adding a path attribute to the Context element, but that didn't help.

If anyone can clarify how to use this, I would greatly appreciate it.

Thanks in advance,
-bob


Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rainer,

On 6/30/2011 5:27 PM, Rainer Jung wrote:
> On 30.06.2011 22:50, Christopher Schultz wrote:
>> Konstantin,
>>
>> On 6/30/2011 11:27 AM, Konstantin Kolinko wrote:
>>> 2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>>>>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
>>
>>> The above should be an absolute path.
>>
>>> You can use system variables, e.g.
>>> ${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar
>>
>> Hmm... does that mean that VirtualWebappLoader can't be used with paths
>> inside WAR files? Being able to support paths relative to the webapp
>> would be quite nice.
> 
> I always thought the main use case for VWL is to be able to extend wars
> by adding things outside without patching them into the war. So sticking
> to one identical war and adding variations about the deployment
> environment, like resources needed for configuration, on the outside.

That's a good point: if you need truly exotic class loading
requirements, such as being able to re-load certain libraries for only a
portion of your webapp (a la JSP or AXIS services), then using VWL isn't
really what you're looking for.

> If you add classes, ressources or jar files inside the war, then I don't
> see any obvious reason not to include them in the standard places.

If the VirtualWebappLoader allowed certain JARs to be placed /before/
WEB-INF/classes and WEB-INF/lib/*.jar, then a webapp could also include
external patches without modifying the WAR.

I'm not sure that's a truly useful feature, though ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4NKQUACgkQ9CaO5/Lv0PB5jwCgpOdbCTpia9w/xkZ1IiqNtSNT
aVgAn0g5EWfP7fqV4K7FaW+oebiEt4FD
=fClj
-----END PGP SIGNATURE-----

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


Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Rainer Jung <ra...@kippdata.de>.
On 30.06.2011 22:50, Christopher Schultz wrote:
> Konstantin,
> 
> On 6/30/2011 11:27 AM, Konstantin Kolinko wrote:
>> 2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>>>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
> 
>> The above should be an absolute path.
> 
>> You can use system variables, e.g.
>> ${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar
> 
> Hmm... does that mean that VirtualWebappLoader can't be used with paths
> inside WAR files? Being able to support paths relative to the webapp
> would be quite nice.

I always thought the main use case for VWL is to be able to extend wars
by adding things outside without patching them into the war. So sticking
to one identical war and adding variations about the deployment
environment, like ressources needed for configuration, on the outside.

If you add classes, ressources or jar files inside the war, then I don't
see any obvious reason not to include them in the standard places.

Regards,

Rainer

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


RE: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Bob DeRemer <bo...@thingworx.com>.
Awesome, thanks!

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Thursday, June 30, 2011 10:18 PM
To: Tomcat Users List
Subject: Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob,

On 6/30/2011 10:07 PM, Bob DeRemer wrote:
> Thanks!  I know it's all open and online, I was just hoping someone 
> might be able to point me to some specific classes so I don't have to 
> pour through a lot of irrelevant code.

Tomcat's component for JSPs is called Jasper. Most of it can be found in the org.apache.jasper package and subpackages, bundled along with the rest of the Tomcat code.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4NLmwACgkQ9CaO5/Lv0PCQHwCdEQiiqlp6ooaR6ydHE4uTMtFe
HEsAoI2koCSUSozQT4sKJ5tTUMTZxKiU
=yAtC
-----END PGP SIGNATURE-----

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


Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob,

On 6/30/2011 10:07 PM, Bob DeRemer wrote:
> Thanks!  I know it's all open and online, I was just hoping someone
> might be able to point me to some specific classes so I don't have to
> pour through a lot of irrelevant code.

Tomcat's component for JSPs is called Jasper. Most of it can be found in
the org.apache.jasper package and subpackages, bundled along with the
rest of the Tomcat code.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4NLmwACgkQ9CaO5/Lv0PCQHwCdEQiiqlp6ooaR6ydHE4uTMtFe
HEsAoI2koCSUSozQT4sKJ5tTUMTZxKiU
=yAtC
-----END PGP SIGNATURE-----

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


RE: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Bob DeRemer <bo...@thingworx.com>.
Thanks!  I know it's all open and online, I was just hoping someone might be able to point me to some specific classes so I don't have to pour through a lot of irrelevant code.

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Thursday, June 30, 2011 10:04 PM
To: Tomcat Users List
Subject: Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob,

On 6/30/2011 9:55 PM, Bob DeRemer wrote:
> I've verified that the WEB-INF/extensions will work, too.  The key 
> issue for us is being able to hot-deploy extension JAR(s) live without 
> restarting the webapp or Tomcat.  I began by seeing if Tomcat 
> supported find JAR(s) on non-standard locations so we can separate the 
> extensions.  These extensions to our core product will typically be 
> developed by 3rd parties.
> 
> So, I now need to look at creating my own classloader [it seems] 
> because even the VWL doesn't monitor for JAR additions and 
> automatically load them.  Again - if anyone knows how to do this, I 
> would really appreciate any direction to shorten my dev time.

Tomcat has a ClassLoader used for re-loading JSPs. A quick look at that shows there is no real magic there: it does not re-load itself in any way. Instead, some other component somewhere must be monitoring the JSP files for updates and orchestrating the disposal of the old ClassLoader (and the classes and instances loaded by it) and the creation of a new one.

I believe AXIS also has such a scheme for re-loading web services without bouncing the entire webapp.

All source code is available online, so you are free to read it all ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4NKxkACgkQ9CaO5/Lv0PBHdgCdEKO+q78Bg2sKCTHqo3j35Zw8
HC4An0CsvndY6prfajI/jrI45h7T2bF/
=GEfb
-----END PGP SIGNATURE-----

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


Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob,

On 6/30/2011 9:55 PM, Bob DeRemer wrote:
> I've verified that the WEB-INF/extensions will work, too.  The key
> issue for us is being able to hot-deploy extension JAR(s) live
> without restarting the webapp or Tomcat.  I began by seeing if Tomcat
> supported find JAR(s) on non-standard locations so we can separate
> the extensions.  These extensions to our core product will typically
> be developed by 3rd parties.
> 
> So, I now need to look at creating my own classloader [it seems]
> because even the VWL doesn't monitor for JAR additions and
> automatically load them.  Again - if anyone knows how to do this, I
> would really appreciate any direction to shorten my dev time.

Tomcat has a ClassLoader used for re-loading JSPs. A quick look at that
shows there is no real magic there: it does not re-load itself in any
way. Instead, some other component somewhere must be monitoring the JSP
files for updates and orchestrating the disposal of the old ClassLoader
(and the classes and instances loaded by it) and the creation of a new one.

I believe AXIS also has such a scheme for re-loading web services
without bouncing the entire webapp.

All source code is available online, so you are free to read it all ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4NKxkACgkQ9CaO5/Lv0PBHdgCdEKO+q78Bg2sKCTHqo3j35Zw8
HC4An0CsvndY6prfajI/jrI45h7T2bF/
=GEfb
-----END PGP SIGNATURE-----

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


RE: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Bob DeRemer <bo...@thingworx.com>.
I've verified that the WEB-INF/extensions will work, too.  The key issue for us is being able to hot-deploy extension JAR(s) live without restarting the webapp or Tomcat.  I began by seeing if Tomcat supported find JAR(s) on non-standard locations so we can separate the extensions.  These extensions to our core product will typically be developed by 3rd parties.

So, I now need to look at creating my own classloader [it seems] because even the VWL doesn't monitor for JAR additions and automatically load them.  Again - if anyone knows how to do this, I would really appreciate any direction to shorten my dev time.

Thanks,
Bob

-----Original Message-----
From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com] 
Sent: Thursday, June 30, 2011 7:17 PM
To: Tomcat Users List
Subject: Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

2011/7/1 Christopher Schultz <ch...@christopherschultz.net>:
>
> On 6/30/2011 11:27 AM, Konstantin Kolinko wrote:
>> 2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>>>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
>>
>> The above should be an absolute path.
>>
>> You can use system variables, e.g.
>> ${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar
>
> Hmm... does that mean that VirtualWebappLoader can't be used with 
> paths inside WAR files? Being able to support paths relative to the 
> webapp would be quite nice.

I think that should be some ${} property.

It either has
a) either to be given to the Digester when it parses the XML, so that it expands the property,
b) or Digester will leave it unexpanded (because it is unknown) and VirtualWebappLoader  will expand its value when starting.

Either way, there is a question of obtaining this path early and passing this information around.


Regarding the issue that I mentioned:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47939

It looks that the following (without "lib") will work:
 ${catalina.base}/webapps/mywebapp/WEB-INF/extensions/*.jar

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
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 use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/7/1 Christopher Schultz <ch...@christopherschultz.net>:
>
> On 6/30/2011 11:27 AM, Konstantin Kolinko wrote:
>> 2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>>>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
>>
>> The above should be an absolute path.
>>
>> You can use system variables, e.g.
>> ${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar
>
> Hmm... does that mean that VirtualWebappLoader can't be used with paths
> inside WAR files? Being able to support paths relative to the webapp
> would be quite nice.

I think that should be some ${} property.

It either has
a) either to be given to the Digester when it parses the XML, so that
it expands the property,
b) or Digester will leave it unexpanded (because it is unknown) and
VirtualWebappLoader  will expand its value when starting.

Either way, there is a question of obtaining this path early and
passing this information around.


Regarding the issue that I mentioned:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47939

It looks that the following (without "lib") will work:
 ${catalina.base}/webapps/mywebapp/WEB-INF/extensions/*.jar

Best regards,
Konstantin Kolinko

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


Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Konstantin,

On 6/30/2011 11:27 AM, Konstantin Kolinko wrote:
> 2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>
> 
> The above should be an absolute path.
> 
> You can use system variables, e.g.
> ${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar

Hmm... does that mean that VirtualWebappLoader can't be used with paths
inside WAR files? Being able to support paths relative to the webapp
would be quite nice.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4M4YsACgkQ9CaO5/Lv0PCHSACaA5DArmMnC71gtPDOiyEsxoWT
/HoAoI3+0tIrwlcL70SIuj0LnBCZ/S54
=ECep
-----END PGP SIGNATURE-----

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


RE: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Bob DeRemer <bo...@thingworx.com>.
Thanks Konstantin, but that didn't do it.  I can see that Tomcat copies the context.xml over to <tomcat>/conf/Catalina/localhost and names it <mywebapp>.xml.  Is there any way to printout the classpath my webapp is using in the context of tomcat - to try and debug this?

The exact contents is:

<Context path="/Bob">
	<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
		  virtualClasspath="${catalina.base}/webapps/Bob/WEB-INF/lib/extensions/*.jar" />
</Context>

Do I need to do anything programmatically to enable this?

-bob

-----Original Message-----
From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com] 
Sent: Thursday, June 30, 2011 11:27 AM
To: Tomcat Users List
Subject: Re: how to use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>

The above should be an absolute path.

You can use system variables, e.g.
${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar

---------------------------------------------------------------------
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 use VirtualWebappLoader - either in META-INF/context.xml or programmatically on startup

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/6/30 Bob DeRemer <bo...@thingworx.com>:
>           virtualClasspath="/WEB-INF/lib/extensions/*.jar"/>

The above should be an absolute path.

You can use system variables, e.g.
${catalina.base}/webapps/mywebapp/WEB-INF/lib/extensions/*.jar

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