You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Garret Wilson <ga...@globalmentor.com> on 2004/09/06 17:42:48 UTC

missing resource bundle shouldn't be

I just installed Tomcat 5.5.0 on Windows XP Professional SP2. I have an 
existing application that worked under Tomcat 4.x. It consists of a 
servlet in a jar file located here:

\tomcat\common\lib\myservlet.jar

That jar contains a servlet mapped to, for example:

<servlet-mapping>
   <servlet-name>myservlet</servlet-name>
   <url-pattern>/myservlet/test</url-pattern>
</servlet-mapping>

I have a resource bundle installed here:

...mywebapp\WEB-INF\classes\myresourcebundle.properties

My JSP files do the following with no problem:

ResourceBundle.getBundle("myresourcebundle");

However, when my servlet in my jar tries to execute the exact same code, 
I get:

java.util.MissingResourceException: Can't find bundle for base name 
myresourcebundle, locale en_US
	java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:837)
	java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:727)
	java.util.ResourceBundle.getBundle(ResourceBundle.java:577)

[etc.]

* I've tried taking my servlet out of a jar and putting it in 
...mywebapp\WEB-INF\classes\

* I've tried copying my resource bundles to ...mywebapp\WEB-INF\classes\ 
to the same subdirectory as the actual classfiles (even though I'm using 
a non-hierarchical resource bundle name: "myresourcebundle")

* I've tried creating an explicit myresourcebundle_en_US.properties

The only thing that works is to comment out the 
ResourceBundle.getBundle(); line from my servlet.

I've looked at the generated JSP source code from Tomcat, and they have 
the same ResourceBundle.getBundle(); as does my servlet.

Why can my JSP files find my resource bundle, yet my servlet can't?

Garret

P.S. I'm sure that this worked under Tomcat 4.x. Then again, Tomcat 4.x 
didn't issue an error when my JSP files imported a class but didn't use 
it, either.


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


Re: missing resource bundle shouldn't be---solved

Posted by Garret Wilson <ga...@globalmentor.com>.
QM wrote:
> On Mon, Sep 06, 2004 at 02:55:13PM -0700, Garret Wilson wrote:
> : I was planning on using the same set of libraries for multiple web 
> : apps---the jar in question had more than just servlets for a single web app.
> 
> There's no need to do this, really.  Webapps are supposed to be
> self-contained.  My inner C++ developer says I should share common code,
> similar to shared libraries; but C and C++ != Java. =)  I tend to leave
> common/lib/ alone, so only the Tomcat-provided JARs exist there.

I just downloaded an electronic copy of _Professional Apache Tomcat 5_, 
which has a wonderful "Chapter 9: Class Loaders." It turns out that 
there's one classloader for common/lib and common/classes, and another 
for shared/lib and shared/classes. My common routines apparently should 
go into the latter pair---the former pair are intended for API libraries 
like jsp-api.jar and jsf-api.jar.

My servlets, though, should go in WEB-INF/lib and 
WEB-INF/classes---which use yet another classloader, the same one used 
by JSPs. I transferred my servlet jar to WEB-INF/lib, and everything 
worked like a charm.

I know that I reported that I had already tried this. I thought I did. 
Then again, there's so many /lib directories running around that maybe I 
picked the wrong one when I was trying 1,001 possible solutions.

Thanks so much for your and George's feedback, pointing me in the right 
direction. I definitely also recommend _Professional Apache Tomcat 5_.

Cheers,

Garret

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


Re: missing resource bundle shouldn't be

Posted by QM <qm...@brandxdev.net>.
On Mon, Sep 06, 2004 at 02:55:13PM -0700, Garret Wilson wrote:
: I'll try that---it wouldn't cache a jar, would it?

Maybe, maybe not.  I see from your first message that you're running
Tomcat 5.5, which is technically in alpha state.  If you're trying it
out to report issues to the developers, great; but if you're simply
trying out a v5.x release, 5.0.x is considered stable.

Furthermore, I see you're running JDK 1.5.  Has anything changed there
w/r/t ResourceBundles and I18N?  Doubtful, but worth a look.

I know my apps running under Tomcat 5.0.28 / JDK 1.4.x don't have this
problem.  The servlets -- techically, Struts Action classes -- load
ResourceBundles and other objects out of WEB-INF/classes without a
problem.


: I was planning on using the same set of libraries for multiple web 
: apps---the jar in question had more than just servlets for a single web app.

There's no need to do this, really.  Webapps are supposed to be
self-contained.  My inner C++ developer says I should share common code,
similar to shared libraries; but C and C++ != Java. =)  I tend to leave
common/lib/ alone, so only the Tomcat-provided JARs exist there.


: Surely the web container doesn't use a different classloader for 
: container-generated servlets and user-created servlets in the same 
: context---does it? (And if it does, where should I put my resource 
: bundles so that the user-created servlets can access them?)

Don't quote me on this, but IIRC there is a separate classloader for
compiled JSPs to help with GC due to the fact that a classloader can't
be GC'd until all classes it owns have been GC'd. Remember, though,
Tomcat (and other containers) stack certain classloaders for a
Chain-of-Responsibility pattern effect.

Really, I'm at a loss for why it wouldn't work for you, outside of the
fact that you're using Tomcat 5.5 and JDK 1.5.


As a quick test, what about loading *any* data out of the class?  Does a
raw getResourceAsStream() work for you, for the sake of testing?

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


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


Re: missing resource bundle shouldn't be

Posted by Garret Wilson <ga...@globalmentor.com>.
QM wrote:
> : Then what's the solution? I've tried moving the jar from common/lib to 
> : WEB-INF/lib, but that didn't help. Unjarring the files into 
> : WEB-INF/classes didn't work, either.
> 
> When you say "the jar," you mean "the jar containing my servlet
> classes," correct?

Right.

 > That should work.  You restarted Tomcat after this
> change, right?

And restarted and shutdown and started and restarted... :)

> You could also clear the work/ dir to be certain.

I'll try that---it wouldn't cache a jar, would it?

> -and if I may ask, why'd you put the servlet classes in common/lib?

I was planning on using the same set of libraries for multiple web 
apps---the jar in question had more than just servlets for a single web app.

But, to take this issue out of the equation, I've tried putting the jar 
in WEB-INF/lib (where I assume you would say it should go) to no avail.

> : How can I programmatically reference the appropriate classloader from 
> : within my servlet so that I can access property files in 
> : WEB-INF/classes?
> 
> You don't. =) That would, in some sense, defeat the purpose of having
> each webapp live in its own classloader.

Now this doesn't make sense to me. Let's say I have the following JSP:

/index.jsp

This index.jsp file can load resources just fine from WEB-INF/classes.

Now let's say I delete index.jsp and create a class called IndexServlet, 
and map it to /index . From that servlet, I attempt to load a resource 
bundle from WEB-INF/classes---it doesn't work!

But in the first instance the web container takes index.jsp and creates 
its own servlet---*that* is what really gets called from the container. 
If I look in work/ and find the servlet behind index.jsp, I see the same 
code to load a resource bundle from WEB-INF/classes, which works.

So let me restate my question: how can I allow my servlets to load the 
same resource bundle (from the same location) that my JSP can load? 
Because, after all, behind the scenes a JSP *is* a servlet!

Surely the web container doesn't use a different classloader for 
container-generated servlets and user-created servlets in the same 
context---does it? (And if it does, where should I put my resource 
bundles so that the user-created servlets can access them?)

Garret

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


Re: missing resource bundle shouldn't be

Posted by QM <qm...@brandxdev.net>.
On Mon, Sep 06, 2004 at 01:45:27PM -0700, Garret Wilson wrote:
: >Different class loader. The JSP's are running in a class-loader with the
: >application, while the common/lib jars are in a different class-loader 
: >where
: >the WEB-INF/classes are not part of the search path.
: 
: Then what's the solution? I've tried moving the jar from common/lib to 
: WEB-INF/lib, but that didn't help. Unjarring the files into 
: WEB-INF/classes didn't work, either.

When you say "the jar," you mean "the jar containing my servlet
classes," correct?  That should work.  You restarted Tomcat after this
change, right?  You could also clear the work/ dir to be certain.

-and if I may ask, why'd you put the servlet classes in common/lib?  


: How can I programmatically reference the appropriate classloader from 
: within my servlet so that I can access property files in 
: WEB-INF/classes?

You don't. =) That would, in some sense, defeat the purpose of having
each webapp live in its own classloader.

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


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


Re: missing resource bundle shouldn't be

Posted by Garret Wilson <ga...@globalmentor.com>.
George,

George Sexton wrote:
> Different class loader. The JSP's are running in a class-loader with the
> application, while the common/lib jars are in a different class-loader where
> the WEB-INF/classes are not part of the search path.

Then what's the solution? I've tried moving the jar from common/lib to 
WEB-INF/lib, but that didn't help. Unjarring the files into 
WEB-INF/classes didn't work, either.

How can I programmatically reference the appropriate classloader from 
within my servlet so that I can access property files in 
WEB-INF/classes? Or should I put my resource bundles somewhere else? It 
seems a shame that my JSP files can access the resource bundles, but my 
servlets can't---when the JSP files get compiled into servlets, anyway.

Garret

>>-----Original Message-----
>>From: Garret Wilson [mailto:garret@globalmentor.com] 
>>Sent: Monday, September 06, 2004 11:40 AM
>>To: tomcat-user@jakarta.apache.org
>>Subject: Re: missing resource bundle shouldn't be
>>
>>Oh, and I'm using JDK 1.5 RC.
>>
>>Garret
>>
>>Garret Wilson wrote:
>>
>>>I just installed Tomcat 5.5.0 on Windows XP Professional 
>>
>>SP2. I have an 
>>
>>>existing application that worked under Tomcat 4.x. It consists of a 
>>>servlet in a jar file located here:
>>>
>>>\tomcat\common\lib\myservlet.jar
>>>
>>>That jar contains a servlet mapped to, for example:
>>>
>>><servlet-mapping>
>>>  <servlet-name>myservlet</servlet-name>
>>>  <url-pattern>/myservlet/test</url-pattern>
>>></servlet-mapping>
>>>
>>>I have a resource bundle installed here:
>>>
>>>...mywebapp\WEB-INF\classes\myresourcebundle.properties
>>>
>>>My JSP files do the following with no problem:
>>>
>>>ResourceBundle.getBundle("myresourcebundle");
>>>
>>>However, when my servlet in my jar tries to execute the 
>>
>>exact same code, 
>>
>>>I get:
>>>
>>>java.util.MissingResourceException: Can't find bundle for base name 
>>>myresourcebundle, locale en_US
>>>    
>>
>>java.util.ResourceBundle.throwMissingResourceException(Resourc
>>eBundle.java:837) 
>>
>>>    java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:727)
>>>    java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
>>>
>>>[etc.]
>>>
>>>* I've tried taking my servlet out of a jar and putting it in 
>>>...mywebapp\WEB-INF\classes\
>>>
>>>* I've tried copying my resource bundles to 
>>
>>...mywebapp\WEB-INF\classes\ 
>>
>>>to the same subdirectory as the actual classfiles (even 
>>
>>though I'm using 
>>
>>>a non-hierarchical resource bundle name: "myresourcebundle")
>>>
>>>* I've tried creating an explicit myresourcebundle_en_US.properties
>>>
>>>The only thing that works is to comment out the 
>>>ResourceBundle.getBundle(); line from my servlet.
>>>
>>>I've looked at the generated JSP source code from Tomcat, 
>>
>>and they have 
>>
>>>the same ResourceBundle.getBundle(); as does my servlet.
>>>
>>>Why can my JSP files find my resource bundle, yet my servlet can't?
>>>
>>>Garret
>>>
>>>P.S. I'm sure that this worked under Tomcat 4.x. Then 
>>
>>again, Tomcat 4.x 
>>
>>>didn't issue an error when my JSP files imported a class 
>>
>>but didn't use 
>>
>>>it, either.
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

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


RE: missing resource bundle shouldn't be

Posted by George Sexton <gs...@mhsoftware.com>.
Different class loader. The JSP's are running in a class-loader with the
application, while the common/lib jars are in a different class-loader where
the WEB-INF/classes are not part of the search path.

George Sexton
MH Software, Inc.
http://www.mhsoftware.com/
Voice: 303 438 9585
  

> -----Original Message-----
> From: Garret Wilson [mailto:garret@globalmentor.com] 
> Sent: Monday, September 06, 2004 11:40 AM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: missing resource bundle shouldn't be
> 
> Oh, and I'm using JDK 1.5 RC.
> 
> Garret
> 
> Garret Wilson wrote:
> > I just installed Tomcat 5.5.0 on Windows XP Professional 
> SP2. I have an 
> > existing application that worked under Tomcat 4.x. It consists of a 
> > servlet in a jar file located here:
> > 
> > \tomcat\common\lib\myservlet.jar
> > 
> > That jar contains a servlet mapped to, for example:
> > 
> > <servlet-mapping>
> >   <servlet-name>myservlet</servlet-name>
> >   <url-pattern>/myservlet/test</url-pattern>
> > </servlet-mapping>
> > 
> > I have a resource bundle installed here:
> > 
> > ...mywebapp\WEB-INF\classes\myresourcebundle.properties
> > 
> > My JSP files do the following with no problem:
> > 
> > ResourceBundle.getBundle("myresourcebundle");
> > 
> > However, when my servlet in my jar tries to execute the 
> exact same code, 
> > I get:
> > 
> > java.util.MissingResourceException: Can't find bundle for base name 
> > myresourcebundle, locale en_US
> >     
> java.util.ResourceBundle.throwMissingResourceException(Resourc
> eBundle.java:837) 
> > 
> >     java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:727)
> >     java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
> > 
> > [etc.]
> > 
> > * I've tried taking my servlet out of a jar and putting it in 
> > ...mywebapp\WEB-INF\classes\
> > 
> > * I've tried copying my resource bundles to 
> ...mywebapp\WEB-INF\classes\ 
> > to the same subdirectory as the actual classfiles (even 
> though I'm using 
> > a non-hierarchical resource bundle name: "myresourcebundle")
> > 
> > * I've tried creating an explicit myresourcebundle_en_US.properties
> > 
> > The only thing that works is to comment out the 
> > ResourceBundle.getBundle(); line from my servlet.
> > 
> > I've looked at the generated JSP source code from Tomcat, 
> and they have 
> > the same ResourceBundle.getBundle(); as does my servlet.
> > 
> > Why can my JSP files find my resource bundle, yet my servlet can't?
> > 
> > Garret
> > 
> > P.S. I'm sure that this worked under Tomcat 4.x. Then 
> again, Tomcat 4.x 
> > didn't issue an error when my JSP files imported a class 
> but didn't use 
> > it, either.
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


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


Re: missing resource bundle shouldn't be

Posted by Garret Wilson <ga...@globalmentor.com>.
Oh, and I'm using JDK 1.5 RC.

Garret

Garret Wilson wrote:
> I just installed Tomcat 5.5.0 on Windows XP Professional SP2. I have an 
> existing application that worked under Tomcat 4.x. It consists of a 
> servlet in a jar file located here:
> 
> \tomcat\common\lib\myservlet.jar
> 
> That jar contains a servlet mapped to, for example:
> 
> <servlet-mapping>
>   <servlet-name>myservlet</servlet-name>
>   <url-pattern>/myservlet/test</url-pattern>
> </servlet-mapping>
> 
> I have a resource bundle installed here:
> 
> ...mywebapp\WEB-INF\classes\myresourcebundle.properties
> 
> My JSP files do the following with no problem:
> 
> ResourceBundle.getBundle("myresourcebundle");
> 
> However, when my servlet in my jar tries to execute the exact same code, 
> I get:
> 
> java.util.MissingResourceException: Can't find bundle for base name 
> myresourcebundle, locale en_US
>     java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:837) 
> 
>     java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:727)
>     java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
> 
> [etc.]
> 
> * I've tried taking my servlet out of a jar and putting it in 
> ...mywebapp\WEB-INF\classes\
> 
> * I've tried copying my resource bundles to ...mywebapp\WEB-INF\classes\ 
> to the same subdirectory as the actual classfiles (even though I'm using 
> a non-hierarchical resource bundle name: "myresourcebundle")
> 
> * I've tried creating an explicit myresourcebundle_en_US.properties
> 
> The only thing that works is to comment out the 
> ResourceBundle.getBundle(); line from my servlet.
> 
> I've looked at the generated JSP source code from Tomcat, and they have 
> the same ResourceBundle.getBundle(); as does my servlet.
> 
> Why can my JSP files find my resource bundle, yet my servlet can't?
> 
> Garret
> 
> P.S. I'm sure that this worked under Tomcat 4.x. Then again, Tomcat 4.x 
> didn't issue an error when my JSP files imported a class but didn't use 
> it, either.
> 
> 

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