An implementation of ResourceBundleProvider, placed in a spi package, is unable to find properties files...
up vote
0
down vote
favorite
I am new to the Java module system, and I search to migrate my code to it, creating module-info.java
in each project, as soon as they can accept it.
One of the problems I encounter is with resource bundles.
Up to Java 8, I was used to get a property that way for a class A :
ResourceBundle bundle = ResourceBundle.getBundle(A.class.getName(),
(locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
(the underlying cause of this choice was to avoid a big properties file with hundred or thousand messages, difficult to sort. At the time we need to translate a part of our application, we only send the properties files of the objects that have messages that need to be translated in a foreign language.
Our messages coming from properties are not used by a web page, but are written later in reports of a batch process).
However, that code doesn't work anymore when I start its integration into modules, adding a module-info.java
in my projects.
A class B from project M2 do some internal checkings. For that it uses some of its base class implementation : A from project M1.
However, when an error is detected it fails now to retrieve the com.mythematic.m1.A
bundle leading to the folder where files such as com/mythematic/m1/A.properties
, A_fr.properties
, A_en.properties
... are.
I red the question posted on Stackoverflow (How to get ResourceBundle from another Module in Java 9?) and followed the javadocs of JDK 11 after that.
I attempted to create in my project M1 a new package : com.mythematic.m1.spi
containing a AProvider
class implementing ResourceBundleProvider
.
package com.mythematic.m1.spi;
import java.util.*;
import java.util.spi.*;
/**
* Resource provider for A.
*/
public class AProvider extends AbstractResourceBundleProvider {
/** Default property file. */
public AProvider() {
super("A.properties");
}
@Override
public ResourceBundle getBundle(String baseName, Locale locale) {
return super.getBundle(baseName, locale);
}
}
But my bundle is still not found.
I tried these callings :
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getModule().getClassLoader());
But without success. When an instance of the B class has an error in module M2, the A class in module M1 is still unable to read its own bundle and a debug point sat on return super.getBundle(baseName, locale)
doesn't even break on it : My provider is not detected or used.
Over the Internet, I see only the Javadocs of JDK 9
to 11
telling the principles of what has to be done to make ResourceBundleProvider
working with a spi package. But I haven't found any sample using them that work at the moment and I don't know what I am missing.
I red somewhere something about opens
or uses
that should also be added in the module-info.java
of my M2 project, but I am a bit lost now.
Have you experienced ResourceBundleProvider
already and know how they are to be set in Java 9 - 11 ?
And more than that, if I dare... A working exemple showing a module M2 accessing the ressources of a module M1 ?
Regards,
java
add a comment |
up vote
0
down vote
favorite
I am new to the Java module system, and I search to migrate my code to it, creating module-info.java
in each project, as soon as they can accept it.
One of the problems I encounter is with resource bundles.
Up to Java 8, I was used to get a property that way for a class A :
ResourceBundle bundle = ResourceBundle.getBundle(A.class.getName(),
(locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
(the underlying cause of this choice was to avoid a big properties file with hundred or thousand messages, difficult to sort. At the time we need to translate a part of our application, we only send the properties files of the objects that have messages that need to be translated in a foreign language.
Our messages coming from properties are not used by a web page, but are written later in reports of a batch process).
However, that code doesn't work anymore when I start its integration into modules, adding a module-info.java
in my projects.
A class B from project M2 do some internal checkings. For that it uses some of its base class implementation : A from project M1.
However, when an error is detected it fails now to retrieve the com.mythematic.m1.A
bundle leading to the folder where files such as com/mythematic/m1/A.properties
, A_fr.properties
, A_en.properties
... are.
I red the question posted on Stackoverflow (How to get ResourceBundle from another Module in Java 9?) and followed the javadocs of JDK 11 after that.
I attempted to create in my project M1 a new package : com.mythematic.m1.spi
containing a AProvider
class implementing ResourceBundleProvider
.
package com.mythematic.m1.spi;
import java.util.*;
import java.util.spi.*;
/**
* Resource provider for A.
*/
public class AProvider extends AbstractResourceBundleProvider {
/** Default property file. */
public AProvider() {
super("A.properties");
}
@Override
public ResourceBundle getBundle(String baseName, Locale locale) {
return super.getBundle(baseName, locale);
}
}
But my bundle is still not found.
I tried these callings :
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getModule().getClassLoader());
But without success. When an instance of the B class has an error in module M2, the A class in module M1 is still unable to read its own bundle and a debug point sat on return super.getBundle(baseName, locale)
doesn't even break on it : My provider is not detected or used.
Over the Internet, I see only the Javadocs of JDK 9
to 11
telling the principles of what has to be done to make ResourceBundleProvider
working with a spi package. But I haven't found any sample using them that work at the moment and I don't know what I am missing.
I red somewhere something about opens
or uses
that should also be added in the module-info.java
of my M2 project, but I am a bit lost now.
Have you experienced ResourceBundleProvider
already and know how they are to be set in Java 9 - 11 ?
And more than that, if I dare... A working exemple showing a module M2 accessing the ressources of a module M1 ?
Regards,
java
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am new to the Java module system, and I search to migrate my code to it, creating module-info.java
in each project, as soon as they can accept it.
One of the problems I encounter is with resource bundles.
Up to Java 8, I was used to get a property that way for a class A :
ResourceBundle bundle = ResourceBundle.getBundle(A.class.getName(),
(locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
(the underlying cause of this choice was to avoid a big properties file with hundred or thousand messages, difficult to sort. At the time we need to translate a part of our application, we only send the properties files of the objects that have messages that need to be translated in a foreign language.
Our messages coming from properties are not used by a web page, but are written later in reports of a batch process).
However, that code doesn't work anymore when I start its integration into modules, adding a module-info.java
in my projects.
A class B from project M2 do some internal checkings. For that it uses some of its base class implementation : A from project M1.
However, when an error is detected it fails now to retrieve the com.mythematic.m1.A
bundle leading to the folder where files such as com/mythematic/m1/A.properties
, A_fr.properties
, A_en.properties
... are.
I red the question posted on Stackoverflow (How to get ResourceBundle from another Module in Java 9?) and followed the javadocs of JDK 11 after that.
I attempted to create in my project M1 a new package : com.mythematic.m1.spi
containing a AProvider
class implementing ResourceBundleProvider
.
package com.mythematic.m1.spi;
import java.util.*;
import java.util.spi.*;
/**
* Resource provider for A.
*/
public class AProvider extends AbstractResourceBundleProvider {
/** Default property file. */
public AProvider() {
super("A.properties");
}
@Override
public ResourceBundle getBundle(String baseName, Locale locale) {
return super.getBundle(baseName, locale);
}
}
But my bundle is still not found.
I tried these callings :
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getModule().getClassLoader());
But without success. When an instance of the B class has an error in module M2, the A class in module M1 is still unable to read its own bundle and a debug point sat on return super.getBundle(baseName, locale)
doesn't even break on it : My provider is not detected or used.
Over the Internet, I see only the Javadocs of JDK 9
to 11
telling the principles of what has to be done to make ResourceBundleProvider
working with a spi package. But I haven't found any sample using them that work at the moment and I don't know what I am missing.
I red somewhere something about opens
or uses
that should also be added in the module-info.java
of my M2 project, but I am a bit lost now.
Have you experienced ResourceBundleProvider
already and know how they are to be set in Java 9 - 11 ?
And more than that, if I dare... A working exemple showing a module M2 accessing the ressources of a module M1 ?
Regards,
java
I am new to the Java module system, and I search to migrate my code to it, creating module-info.java
in each project, as soon as they can accept it.
One of the problems I encounter is with resource bundles.
Up to Java 8, I was used to get a property that way for a class A :
ResourceBundle bundle = ResourceBundle.getBundle(A.class.getName(),
(locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
(the underlying cause of this choice was to avoid a big properties file with hundred or thousand messages, difficult to sort. At the time we need to translate a part of our application, we only send the properties files of the objects that have messages that need to be translated in a foreign language.
Our messages coming from properties are not used by a web page, but are written later in reports of a batch process).
However, that code doesn't work anymore when I start its integration into modules, adding a module-info.java
in my projects.
A class B from project M2 do some internal checkings. For that it uses some of its base class implementation : A from project M1.
However, when an error is detected it fails now to retrieve the com.mythematic.m1.A
bundle leading to the folder where files such as com/mythematic/m1/A.properties
, A_fr.properties
, A_en.properties
... are.
I red the question posted on Stackoverflow (How to get ResourceBundle from another Module in Java 9?) and followed the javadocs of JDK 11 after that.
I attempted to create in my project M1 a new package : com.mythematic.m1.spi
containing a AProvider
class implementing ResourceBundleProvider
.
package com.mythematic.m1.spi;
import java.util.*;
import java.util.spi.*;
/**
* Resource provider for A.
*/
public class AProvider extends AbstractResourceBundleProvider {
/** Default property file. */
public AProvider() {
super("A.properties");
}
@Override
public ResourceBundle getBundle(String baseName, Locale locale) {
return super.getBundle(baseName, locale);
}
}
But my bundle is still not found.
I tried these callings :
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getClassLoader());
ResourceBundle.getBundle(A.class.getName(), (locale != null) ? locale : Locale.getDefault(), A.class.getModule().getClassLoader());
But without success. When an instance of the B class has an error in module M2, the A class in module M1 is still unable to read its own bundle and a debug point sat on return super.getBundle(baseName, locale)
doesn't even break on it : My provider is not detected or used.
Over the Internet, I see only the Javadocs of JDK 9
to 11
telling the principles of what has to be done to make ResourceBundleProvider
working with a spi package. But I haven't found any sample using them that work at the moment and I don't know what I am missing.
I red somewhere something about opens
or uses
that should also be added in the module-info.java
of my M2 project, but I am a bit lost now.
Have you experienced ResourceBundleProvider
already and know how they are to be set in Java 9 - 11 ?
And more than that, if I dare... A working exemple showing a module M2 accessing the ressources of a module M1 ?
Regards,
java
java
edited Nov 11 at 8:02
asked Nov 11 at 7:47
Marc
8918
8918
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246796%2fan-implementation-of-resourcebundleprovider-placed-in-a-spi-package-is-unable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown