cross-jars resource bundles

M

Marco

Hi all,

I am struggling with the Java interfaces about resource bundles. I've
written a simple class that works like this:

public class i18n
{
private static final String BUNDLE_NAME = "user_messages";
private static final ResourceBundle RESOURCE_BUNDLE =
ResourceBundle.getBundle ( BUNDLE_NAME );

/** Gets the message pattern corresponding to the key and apply it to
the other arguments. */
public static String msg ( String key, Object... args )
}

I've put a test file "user_message.properties" in the same jar where
this class is, let's say it is i18n.jar. As long as I am using the
same jar, all works fine. Now, I want to use the class above in
another jar, let's say app.jar (by passing both to java's -cp option),
where there is another copy of user_messages.properties, that should
be used in place of the original one.

Well, that doesn't happen at all, only the messages in the original
i18n.jar are recognized. Is there any way to load a bundle that is in
one jar, with code that is in another jar? For the moment I am just
removing any user_messages.properties from i18n.jar, but I'd rather
not to do it and I'd like to understand more about the issue.

Thanks in advance for any help.

Marco.
 
J

John B. Matthews

[...]
I've put a test file "user_message.properties" in the same jar where
this class is, let's say it is i18n.jar. As long as I am using the
same jar, all works fine. Now, I want to use the class above in
another jar, let's say app.jar (by passing both to java's -cp
option), where there is another copy of user_messages.properties,
that should be used in place of the original one.

Well, that doesn't happen at all, only the messages in the original
i18n.jar are recognized. Is there any way to load a bundle that is in
one jar, with code that is in another jar? For the moment I am just
removing any user_messages.properties from i18n.jar, but I'd rather
not to do it and I'd like to understand more about the issue.

Java's -cp option is ignored when running from a JAR, but you can
specify a Class-Path in the manifest:

<http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html>
<http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html>
 
M

Marco Brandizi

Java's -cp option is ignored when running from a JAR, but you can
specify a Class-Path in the manifest:

<http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html>
<http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html>

Thanks John, but I don't think it's what I need.

I don't want to specify app.jar inside i18n.jar. Indeed I don't want
the opposite either, since here I am describing a simplified case, the
general case is i18n.jar contains basic utilities that are going to be
used by several other packages I am not even aware of (and all will be
packaged by Maven). The problem I have is basically having a class in
a core library that loads resource bundles from a specifc jar that
uses the core lib, because it is being called from the dependent
library.

Best,
M.
 
M

Marco Brandizi

Did you put app.jar before i18n.jar in the classpath?

Thanks Steven.

I suspected this could be a work-around, however I think it's a bit
dirty. The classpath is often not so under control, e.g.: Maven or Ant
build it, or a shell script built it by doing: "for i in *.jar; do
CLASSPATH=$CLASSPATH:$i; done". So, I am seeking for a way to do what
I described, without these CP tricks. I just want that the more
specific bundle (because it's in the same JAR the invoker is) has
precedence.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top