users@glassfish.java.net

RE: Isolate properties files between two WARs in an EAR

From: Wim Verreycken <wim_at_pizzastop.be>
Date: Sun, 24 Aug 2008 17:31:46 +0200

Forwarded this to the glassfish quality list.
Manfred Bien wrote :

"The easiest solution to that problem is to make sure the properties you are
loading for the instantiated class use the getResource method based on the
classloader for each of the web applications."

Here's (old but clearly) what he is talking about :
http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html

Also, the below exert from the servlet spec might get you to fetch the
property files based on their relative path without using a classloader.

If it helps, could you be as kind as to test all three solutions and post
your results for :
Class.getResource
Classloader.getResource
ServletContext.getResource
(All these return URL's)
since we're currently discussing this issue on the quality list as well.
It'll help improve glassfish v3 and future versions.

Many thanks in advance,

Wim
--------
JSR-154 exert
--------
ServletContext
        public java.net.URL getResource(java.lang.String path)
        throws MalformedURLException
Returns a URL to the resource that is mapped to a specified path. The path
must begin with a "/" and is interpreted as relative to the current context
root.
This method allows the servlet container to make a resource available to
servlets
from any source. Resources can be located on a local or remote file system,
in a database, or in a .war file.
The servlet container must implement the URL handlers and URLConnection
objects that are necessary to access the resource.
This method returns null if no resource is mapped to the pathname.
Some containers may allow writing to the URL returned by this method using
the methods of the URL class.

The resource content is returned directly, so be aware that requesting a
.jsp
page returns the JSP source code. Use a RequestDispatcher instead to
include results of an execution.
This method has a different purpose than java.lang.Class.getResource,
which looks up resources based on a class loader. This method does not use
class loaders.
------





-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: vrijdag 22 augustus 2008 23:07
To: users_at_glassfish.dev.java.net
Subject: Isolate properties files between two WARs in an EAR

Hi!

I am using glassfish v2 and have an EAR application with two WARs inside. I
put all the jars common to both in the EAR root level and only the specific
jars inside each WAR WEB-INF/lib.

I have a library (displaytag.jar) in the two WARs and the configuration of
displaytag is made by a properties file. Because each of the WARs have
different configurations, I put a displaytag.properties file in each
WEB-INF/classes and a displaytag.jar in each WEB-INF/lib.

The problem is that when one application loads the displaytag.properties,
the other uses the same properties, ignoring its own properties file. Is
there a way to solve this problem without using the class-loader
delegate="false" configuration in sun-web.xml?

If I use class-loader delegate="false" my application begin to have problems
with ClassCastExceptions. In this case, should I put all the jars, its
dependencies and resources (xml, properties files) in the same classloader?

Thanks!
[Message sent by forum member 'renato_rka' (renato_rka)]

http://forums.java.net/jive/thread.jspa?messageID=294915

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net