How to integrate CharsetProvider in JBoss EAP 6
Environment
- RedHat JBoss Enterprise Application Platform (EAP)
- 6.x
Issue
- How to integrate our own written CharsetProvider into JBoss EAP 6.? With JBoss EAP 5 our ownCharsetProvider.jar was copied to the \lib folder and it works. How to do the same in EAP 6?
Resolution
- The API documentation at [1] https://docs.oracle.com/javase/7/docs/api/java/nio/charset/spi/CharsetProvider.html states: A charset provider is a concrete subclass of this class that has a zero-argument constructor and some number of associated charset implementation classes. Charset providers may be installed in an instance of the Java platform as extensions, that is, jar files placed into any of the usual extension directories. Providers may also be made available by adding them to the applet or application class path or by some other platform-specific means. Charset providers are looked up via the current thread's context class loader.
-
However the one at https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html states :
The map returned by this method will have one entry for each charset for which support is available in the current Java virtual machine. If two or more supported charsets have the same canonical name then the resulting map will contain just one of them; which one it will contain is not specified. -
That looks to be inconsistent whether the lookups are supposed to by default occur using the Thread-context classloader (TCCL) or only JVM-wide ones (installed using JRE extension mechanisms). Looking at the source code for OpenJDK, which should closely match Oracle JDK, it does in fact use only the system classloader and not the TCCL.
- It worked on EAP 5 because the lib dir was added to the system classloader, but on EAP 6 the only thing there is jboss-modules.jar.
- Using the standard Java extension mechanism, you should be able to put the jar somewhere and add -Djava.ext.dirs=/path/to/lib-ext to JAVA_OPTS, specifying the path to the directory it is in (not the jar itself). It will however not have access to any classes other than the JDK ones.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
