java - Spring boot 1.4.x and custom CharsetProvider -


i'm trying register custom charsetprovider able use x-gsm7bit encoding. use https://github.com/opensmpp/opensmpp/tree/master/charset/src/main/java/org/smpp/charset provider logica. register new charset provider use meta-inf/services/java.nio.charsets.spi.charsetprovider file content org.smpp.charset.gsm7bitcharsetprovider.

i can't make working. sources of test application here https://github.com/asmsoft/provider

i java.util.serviceconfigurationerror: java.nio.charset.spi.charsetprovider: provider org.smpp.charset.gsm7bitcharsetprovider not found when start fat jar

mvn clean mvn package java -jar target/provider-1.0-snapshot.jar 

if start mvn spring-boot:run java.io.unsupportedencodingexception: x-gsm7bit

and works when start application ide.

currently solved problem follows: i've put jar providing custom charset java_home/jre/lib/ext , works expected again, charset being registered on boot.

i'm not happy solution , i'd ask help.

i think you've encountered bug in jdk. javadoc charsetprovider says:

charset providers looked via current thread's context class loader

however, code looks providers tells different story:

classloader cl = classloader.getsystemclassloader(); serviceloader<charsetprovider> sl =     serviceloader.load(charsetprovider.class, cl); 

as can see, it's using system class loader , not thread's context class loader.

it works in ide because application's classes , dependencies available system class loader. when package application in fat jar, fails application's classes , dependencies available spring boot's class loader child of system class loader. you'd have same problem in environment class loader used, example traditional war deployment servlet container.

to avoid problem, need make provider available system class loader. you've discovered, putting jar in java_home/jre/lib/ext 1 way achieve that. other options include using shaded jar rather fat jar, or post-processing fat jar add provider's classes directly root of jar rather nested jar.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -