I published a lite version of Json ResourceBundle to my dormant git repository. Here is a Readme.md copy from that
Registering a custom
ResourceBundle.Control extension forces JSON parser jars to be present in extension directory. This repo provides basic skeleton/raw code to overcome the limitation and support json bundle, natively using SPI and extension mechanism. If you are ok with putting 3rd party parser jars in
java.ext.dir too (or putting your extension in default ext directory), then you don’t need to look further in this git.
Load your json bundle.
java by default provides way to load a ResourceBundle using
ResourceBundle.getBundle(..) api. The default implementation supports a java and properties file ResourceBundle.
A typical usage of API, is explained in java doc:
ResourceBundle myResources = ResourceBundle.getBundle("MyResources", currentLocale);
ResourceBundle myResources = ResourceBundle.getBundle("com.aminur.resourcebundle.muffinapp.bundle");
ResourceBundle myResources = ResourceBundle.getBundle(“MyResources”, currentLocale);
The API supports
java|properties bundle by default. And java also provides way to control other bundles. e.g
However the problem I faced with this approach is that to register the
SPI implementation jar has to be in
java.ext.dir dir. To quote the tutorial:
When you install a Java extension, you typically put the JAR file of the extension in the lib/ext directory of your JRE. However, this command specifies the directory that contains Java extensions with the system property
So far so good. Steps are :
- You register a service implementing
- return a custom implementation of
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
- Place the jar in ext directory, or change the ext directory and your bundle is loaded.
Problem is in step 3. To create a new JsonBundle, we will have to parse Json file. Most of the JSON Parser (GSON/Jackson/..) are third party libary and this approach will force those 3rd party libraries to be present in ext folder. Reason for this is the ext/dir is loaded using
extension classloader unlike your system classloader. And hence the depdendent API for parsing JSON has to be there in extension directory. I tried to solve it using another SPI that provides parsed bundle.
- build project json-resourcebundle-ext and put the jar in the default ext dir or keep a note of folder where you have placed the jar.
- Run the test in json-resourcebundle by specifying
- For netbeans user, there exists nbactions.xml in json-resourcebundle. Define env variable
USER_LOCAL_REPOSITORYto point to your local maven repository and things shall work
- Allama Iqbal – Sele... 41.3k views
- Harappan Culture (Indus V... 26.5k views
- Allama Iqbal – Sele... 20.3k views
- Bhagalpur to Singapore 17.3k views
- Islamic Banking? Whats th... 16.5k views
- Beach Trek Across Arabian... 14.7k views
- Sach hai, Vipatti jab aat... 12.3k views
- I Protest 10.4k views
- O ye who don’t beli... 10k views
- Thread unsafe Format in J... 6.5k views