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,










share|improve this question




























    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,










    share|improve this question


























      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,










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 8:02

























      asked Nov 11 at 7:47









      Marc

      8918




      8918





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma