Spring Boot runnable jar can't load terracotta -
i've been pulling hair out day on one. found workaround want know why it's happening.
i have spring boot app bunch of dependencies (activemq, hibernate, terracotta, etc) runs inside eclipse, , build default spring boot maven plugin:
<build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build>
by typing:
mvn clean package
it builds runnable uberjar , when run it, can see connects activemq, connects database using hibernate, when tries connect terracotta caches get:
caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'datacacheregistry' defined in class path resource [com/algomi/ase/terracotta/datacacheregistryconfig.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [com.algomi.infra.server.datacache.datacacheregistry]: factory method 'datacacheregistry' threw exception; nested exception java.lang.runtimeexception: cannot create module because of error datacache configuration module: asecalculatorrestservice @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:599) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1128) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1023) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:510) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:202) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.config.dependencydescriptor.resolvecandidate(dependencydescriptor.java:207) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1128) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:1056) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.constructorresolver.resolveautowiredargument(constructorresolver.java:835) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.constructorresolver.createargumentarray(constructorresolver.java:741) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] ... 27 common frames omitted caused by: org.springframework.beans.beaninstantiationexception: failed instantiate [com.algomi.infra.server.datacache.datacacheregistry]: factory method 'datacacheregistry' threw exception; nested exception java.lang.runtimeexception: cannot create module because of error datacache configuration module: asecalculatorrestservice @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:189) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:588) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] ... 40 common frames omitted caused by: java.lang.runtimeexception: cannot create module because of error datacache configuration module: asecalculatorrestservice @ com.algomi.infra.server.datacache.datacachefactory.builddatacache(datacachefactory.java:72) ~[infra-server-common-1.2.7.jar!/:1.2.7] @ com.algomi.infra.server.datacache.datacachefactory.builddatacaches(datacachefactory.java:32) ~[infra-server-common-1.2.7.jar!/:1.2.7] @ com.algomi.ase.terracotta.datacacheregistryconfig.datacacheregistry(datacacheregistryconfig.java:23) ~[classes!/:0.0.2-snapshot] @ com.algomi.ase.terracotta.datacacheregistryconfig$$enhancerbyspringcglib$$780857d9.cglib$datacacheregistry$0(<generated>) ~[classes!/:0.0.2-snapshot] @ com.algomi.ase.terracotta.datacacheregistryconfig$$enhancerbyspringcglib$$780857d9$$fastclassbyspringcglib$$35534a1e.invoke(<generated>) ~[classes!/:0.0.2-snapshot] @ org.springframework.cglib.proxy.methodproxy.invokesuper(methodproxy.java:228) ~[spring-core-4.3.3.release.jar!/:4.3.3.release] @ org.springframework.context.annotation.configurationclassenhancer$beanmethodinterceptor.intercept(configurationclassenhancer.java:356) ~[spring-context-4.3.3.release.jar!/:4.3.3.release] @ com.algomi.ase.terracotta.datacacheregistryconfig$$enhancerbyspringcglib$$780857d9.datacacheregistry(<generated>) ~[classes!/:0.0.2-snapshot] @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.8.0_60] @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:1.8.0_60] @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.8.0_60] @ java.lang.reflect.method.invoke(method.java:497) ~[na:1.8.0_60] @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:162) ~[spring-beans-4.3.3.release.jar!/:4.3.3.release] ... 41 common frames omitted caused by: java.lang.reflect.invocationtargetexception: null @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:1.8.0_60] @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) ~[na:1.8.0_60] @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) ~[na:1.8.0_60] @ java.lang.reflect.constructor.newinstance(constructor.java:422) ~[na:1.8.0_60] @ com.algomi.infra.server.datacache.datacachefactory.builddatacache(datacachefactory.java:68) ~[infra-server-common-1.2.7.jar!/:1.2.7] ... 53 common frames omitted caused by: net.sf.ehcache.cacheexception: unable load class net.sf.ehcache.terracotta.standaloneterracottaclusteredinstancefactory. initial cause null @ net.sf.ehcache.util.classloaderutil.createnewinstance(classloaderutil.java:109) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.terracotta.terracottaclusteredinstancehelper.newclusteredinstancefactory(terracottaclusteredinstancehelper.java:176) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.terracotta.terracottaclient.createnewclusteredinstancefactory(terracottaclient.java:186) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.terracotta.terracottaclient.createclusteredinstancefactory(terracottaclient.java:138) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.cachemanager.doinit(cachemanager.java:432) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.cachemanager.init(cachemanager.java:377) ~[ehcache-core-2.6.11.jar!/:na] @ net.sf.ehcache.cachemanager.<init>(cachemanager.java:317) ~[ehcache-core-2.6.11.jar!/:na] @ com.capxd.infra.common.model.ehcachemanager.getcachemanager(ehcachemanager.java:42) ~[messaging-2.1.1.jar!/:na] @ com.capxd.infra.common.model.ehcachemanager.getbackingcache(ehcachemanager.java:27) ~[messaging-2.1.1.jar!/:na] @ com.capxd.infra.common.model.ehcachedatacache.getbackingcache(ehcachedatacache.java:63) ~[messaging-2.1.1.jar!/:na] @ com.capxd.infra.common.model.ehcachedatacache.<init>(ehcachedatacache.java:43) ~[messaging-2.1.1.jar!/:na] ... 58 common frames omitted caused by: java.lang.exceptionininitializererror: null @ net.sf.ehcache.terracotta.standaloneterracottaclusteredinstancefactory.<init>(standaloneterracottaclusteredinstancefactory.java:37) ~[ehcache-terracotta-2.6.11.jar!/:na] @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:1.8.0_60] @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) ~[na:1.8.0_60] @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) ~[na:1.8.0_60] @ java.lang.reflect.constructor.newinstance(constructor.java:422) ~[na:1.8.0_60] @ net.sf.ehcache.util.classloaderutil.createnewinstance(classloaderutil.java:92) ~[ehcache-core-2.6.11.jar!/:na] ... 68 common frames omitted caused by: java.lang.runtimeexception: java.lang.stringindexoutofboundsexception: string index out of range: -1 @ com.terracotta.express.clientfactoryimpl.<init>(clientfactoryimpl.java:93) ~[terracotta-toolkit-1.6-runtime-5.10.0.jar!/:na] @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:1.8.0_60] @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) ~[na:1.8.0_60] @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) ~[na:1.8.0_60] @ java.lang.reflect.constructor.newinstance(constructor.java:422) ~[na:1.8.0_60] @ java.lang.class.newinstance(class.java:442) ~[na:1.8.0_60] @ org.terracotta.express.util.getimplinstance(util.java:11) ~[terracotta-toolkit-1.6-runtime-5.10.0.jar!/:na] @ org.terracotta.express.clientfactory.<clinit>(clientfactory.java:14) ~[terracotta-toolkit-1.6-runtime-5.10.0.jar!/:na] ... 74 common frames omitted caused by: java.lang.stringindexoutofboundsexception: string index out of range: -1 @ java.lang.string.substring(string.java:1931) ~[na:1.8.0_60] @ org.springframework.boot.loader.jar.jarurlconnection.extractfullspec(jarurlconnection.java:257) ~[ase-calculator-rest-service-0.0.2-20161110.103558-5.jar:0.0.2-snapshot] @ org.springframework.boot.loader.jar.jarurlconnection.get(jarurlconnection.java:228) ~[ase-calculator-rest-service-0.0.2-20161110.103558-5.jar:0.0.2-snapshot] @ org.springframework.boot.loader.jar.handler.openconnection(handler.java:88) ~[ase-calculator-rest-service-0.0.2-20161110.103558-5.jar:0.0.2-snapshot] @ java.net.url.openconnection(url.java:972) ~[na:1.8.0_60] @ java.net.url.openstream(url.java:1038) ~[na:1.8.0_60] @ com.terracotta.express.clientfactoryimpl.handlejarurl(clientfactoryimpl.java:102) ~[terracotta-toolkit-1.6-runtime-5.10.0.jar!/:na] @ com.terracotta.express.clientfactoryimpl.<init>(clientfactoryimpl.java:84) ~[terracotta-toolkit-1.6-runtime-5.10.0.jar!/:na] ... 81 common frames omitted
i downloaded source code terracotta, spring loader, , found problem in method:
private static string extractfullspec(url url, string pathfromroot) { string file = url.getfile(); int separatorindex = file.indexof(separator); if (separatorindex < 0) { return ""; } int specindex = separatorindex + separator.length() + pathfromroot.length(); return file.substring(specindex); }
this method in org.springframework.boot.loader.jar.jarurlconnection
in spring-boot-loader-1.4.1.release.jar
. problem seems in incoming parameter url
. following jars (and far can make out every other jar) loads no problem:
file:/c:/dev/repos/state-engine/calculator-rest-service/target/calculator-rest-service-0.0.2-snapshot.jar!/boot-inf/lib/spring-boot-starter-validation-1.4.1.release.jar!/ file:/c:/dev/repos/state-engine/calculator-rest-service/target/calculator-rest-service-0.0.2-snapshot.jar!/boot-inf/lib/evo-inflector-1.2.1.jar!/ file:/c:/dev/repos/state-engine/calculator-rest-service/target/calculator-rest-service-0.0.2-snapshot.jar!/boot-inf/lib/hibernate-c3p0-3.6.10.final.jar!/
but terracotta 1 fails:
file:/c:/dev/repos/state-engine/calculator-rest-service/target/calculator-rest-service-0.0.2-snapshot.jar!/boot-inf/lib/terracotta-toolkit-1.6-runtime-5.10.0.jar!
the stringindexoutofboundsexception
happens because there assumption in method, far can make out, urls end "!/" url terracotta missing trailing '/'.
the workaround add following in pom make launcher propertieslauncher:
<build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <configuration> <layout>zip</layout> </configuration> </plugin> </plugins> </build>
and put terracotta jar in separate libs folder , run jar java -dloader.path=c:/temp/libs/lib -jar xxx
.
this annoying though have have terracotta jar in separate libs folder when every other jar loads fine inside uberjar.
any ideas how uberjar work terracotta inside , using jarlauncher istead of propertieslauncher???
Comments
Post a Comment