Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Spring Boot: Unable to start embedded Tomcat while using maven

Untitled

2022-06-21 10:40:14.696  WARN 10965 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-06-21 10:40:14.708  INFO 10965 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-21 10:40:14.796 ERROR 10965 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.0.jar:2.7.0]
    at com.javatechie.report.SpringBootJasperReportApplication.main(SpringBootJasperReportApplication.java:38) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:104) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.7.0.jar:2.7.0]
    ... 8 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:175) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:170) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:155) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:87) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.7.0.jar:2.7.0]
    ... 13 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 54 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:146) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:832) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:691) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:674) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.(AllEncompassingFormHttpMessageConverter.java:91) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.filter.FormContentFilter.(FormContentFilter.java:61) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.(OrderedFormContentFilter.java:29) ~[spring-boot-2.7.0.jar:2.7.0]
    at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.formContentFilter(WebMvcAutoConfiguration.java:177) ~[spring-boot-autoconfigure-2.7.0.jar:2.7.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 55 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer
    at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.(JavaTimeModule.java:158) ~[jackson-datatype-jsr310-2.13.3.jar:2.13.3]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_191]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_191]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 69 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:42 min
[INFO] Finished at: 2022-06-21T10:40:14+06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.0:run (default-cli) on project spring-boot-jasper-report: Application finished with exit code: 1 -> [Help 1]

This may happen while running:

if accidentally spring-boot-starter-parent dependency is missing from pom.xml:

Make sure Spring Boot Starter Parent dependency is included at the top of pom.xml. Not inside dependencies tag but, before build tag. Like:

which includes spring-boot-starter-tomcat dependency. Also make sure another process not using default tomcat port. If so, change server.port property inside application.properties.

TeaVM : JSoup [ERROR] Method java.nio.charset.Charset.isSupported(Ljava/lang/String;)Z was not found

Untitled

[ERROR] Method java.nio.charset.Charset.isSupported(Ljava/lang/String;)Z was not found
    at org.jsoup.helper.DataUtil.validateCharset(DataUtil.java:280)
    at org.jsoup.helper.DataUtil.getCharsetFromContentType(DataUtil.java:269)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:907)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Method java.nio.charset.Charset.isSupported(Ljava/lang/String;)Z was not found
    at org.jsoup.helper.DataUtil.validateCharset(DataUtil.java:278)
    at org.jsoup.helper.DataUtil.getCharsetFromContentType(DataUtil.java:269)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:907)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.CookieManager was not found
    at org.jsoup.helper.HttpConnection$Request.(HttpConnection.java:661)
    at org.jsoup.helper.HttpConnection.(HttpConnection.java:100)
    at org.jsoup.helper.HttpConnection.connect(HttpConnection.java:80)
    at org.jsoup.Jsoup.connect(Jsoup.java:91)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Method java.net.URL.openConnection(Ljava/net/Proxy;)Ljava/net/URLConnection; was not found
    at org.jsoup.helper.HttpConnection$Response.createConnection(HttpConnection.java:1021)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:856)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.IDN was not found
    at org.jsoup.helper.HttpConnection.punyUrl(HttpConnection.java:147)
    at org.jsoup.helper.HttpConnection.encodeUrl(HttpConnection.java:126)
    at org.jsoup.helper.HttpConnection.encodeUrl(HttpConnection.java:119)
    at org.jsoup.helper.HttpConnection.url(HttpConnection.java:184)
    at org.jsoup.helper.HttpConnection.connect(HttpConnection.java:81)
    at org.jsoup.Jsoup.connect(Jsoup.java:91)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.CookieManager was not found
    at org.jsoup.helper.CookieUtil.applyCookiesToRequest(CookieUtil.java:41)
    at org.jsoup.helper.HttpConnection$Response.createConnection(HttpConnection.java:1033)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:856)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.CookieManager was not found
    at org.jsoup.helper.CookieUtil.storeCookies(CookieUtil.java:87)
    at org.jsoup.helper.HttpConnection$Response.(HttpConnection.java:1074)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:868)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.SocketTimeoutException was not found
    at org.jsoup.internal.ConstrainableInputStream.read(ConstrainableInputStream.java:58)
    at java.util.zip.GZIPInputStream.(TGZIPInputStream.java:56)
    at java.util.zip.GZIPInputStream.(TGZIPInputStream.java:33)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:912)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)
[ERROR] Class java.net.SocketTimeoutException was not found
    at org.jsoup.internal.ConstrainableInputStream.read
    at java.util.zip.GZIPInputStream.(TGZIPInputStream.java:56)
    at java.util.zip.GZIPInputStream.(TGZIPInputStream.java:33)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:912)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
    at com.mohi.Client.main(Client.java:236)

This may happen if you have JSoup version greater than 1.6.3 like:

Replace it with version 1.6.3:

TeaVM version 0.7.0 at the moment does not play well with JSoup versions greater than 1.6.3 yet.

Logging in TeaVM : Unexpected error occurred: java.lang.AssertionError: Variable used before definition:

Untitled

 Error optimizing program for method org.apache.commons.logging.LogFactory.createFactory(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Object;:
var @factoryClass as factoryClass // 1
var @classLoader as classLoader // 2
var @logFactoryClass as logFactoryClass // 3
var @ex as ex // 18
var @e as e // 31
var @implementsLogFactory as implementsLogFactory // 50
var @msg as msg // 51
var @e_1 as e // 75
var @classLoader_1 as classLoader // 93
var @classLoader_2 as classLoader // 94
var @e_2 as e // 99
var @e_3 as e // 100
var @classLoader_3 as classLoader // 105
...
var @classLoader_9 as classLoader // 115
var @e_4 as e // 119
var @ex_1 as ex // 122
$0
    initClass org.apache.commons.logging.LogFactory
    goto $1
$1
  at 'org/apache/commons/logging/LogFactory.java' 1012
    nop
    @logFactoryClass := null
  at unknown location
    goto $35
$2
    @4 := phi @logFactoryClass from $35, @19 from $29, @32 from $25, @48 from $34
  at 'org/apache/commons/logging/LogFactory.java' 1142
    @5 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
    if @5 == 0 then goto $5 else goto $6
    catch java.lang.Exception goto $7
$3
  at 'org/apache/commons/logging/LogFactory.java' 1020
    @88 := new java.lang.NoSuchMethodError
    @89 := 'Method not found: java.lang.ClassLoader.loadClass(Ljava/lang/String;)Ljava/lang/Class;'
    invoke `java.lang.NoSuchMethodError.(Ljava/lang/String;)V` @88, @89
    throw @88
    catch java.lang.ClassNotFoundException goto $4
    catch java.lang.NoClassDefFoundError goto $33
    catch java.lang.ClassCastException goto $34
    catch java.lang.Exception goto $7
$4
    @ex := exception
    @19 := phi @logFactoryClass from $3, @17 from $3
  at 'org/apache/commons/logging/LogFactory.java' 1050
    nop
    @20 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
    if @classLoader !==@20 then goto $29 else goto $30
    catch java.lang.Exception goto $7
$5
  at 'org/apache/commons/logging/LogFactory.java' 1146
    @6 := invokeStatic `java.lang.Class.forName(Ljava/lang/String;)Ljava/lang/Class;` @factoryClass
  at 'org/apache/commons/logging/LogFactory.java' 1147
    @7 := invoke `java.lang.Class.newInstance()Ljava/lang/Object;` @6
  at unknown location
    @133 := nullCheck @6
  at 'org/apache/commons/logging/LogFactory.java' 1147
    @8 := cast @7 to `Lorg/apache/commons/logging/LogFactory;`
  at unknown location
    goto $36
    catch java.lang.Exception goto $7
$6
  at 'org/apache/commons/logging/LogFactory.java' 1143
    @9 := new java.lang.StringBuffer
    invoke `java.lang.StringBuffer.()V` @9
    @10 := 'Unable to load factory class via classloader '
    @11 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @9, @10
    @12 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader_9
    @13 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @11, @12
  at unknown location
    @134 := nullCheck @11
  at 'org/apache/commons/logging/LogFactory.java' 1143
    @14 := ' - trying the classloader associated with this LogFactory.'
    @15 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @13, @14
  at unknown location
    @135 := nullCheck @13
  at 'org/apache/commons/logging/LogFactory.java' 1143
    @16 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @15
  at unknown location
    @136 := nullCheck @15
  at 'org/apache/commons/logging/LogFactory.java' 1143
    invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @16
  at unknown location
    goto $5
    catch java.lang.Exception goto $7
$7
    @e_1 := exception
    @76 := phi @logFactoryClass from $35, @4 from $2, @4 from $5, @133 from $5, @4 from $6, @logFactoryClass from $3, @17 from $3, @19 from $4, @19 from $29, @19 from $30, @19 from $31, @19 from $32, @32 from $33, @32 from $25, @32 from $26, @32 from $27, @32 from $28, @48 from $34, @48 from $16, @48 from $17, @48 from $18, @48 from $19, @48 from $20, @48 from $21, @48 from $22, @48 from $23, @48 from $24
  at 'org/apache/commons/logging/LogFactory.java' 1150
    nop
    @77 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
    if @77 == 0 then goto $8 else goto $9
$8
  at 'org/apache/commons/logging/LogFactory.java' 1153
    if @76 === null then goto $10 else goto $11
$9
  at 'org/apache/commons/logging/LogFactory.java' 1151
    @87 := 'Unable to create LogFactory instance.'
    invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @87
  at unknown location
    goto $8
$10
  at 'org/apache/commons/logging/LogFactory.java' 1158
    @78 := new org.apache.commons.logging.LogConfigurationException
  at 'org/apache/commons/logging/LogConfigurationException.java' 55
    nop
    if @e_1 !== null then goto $37 else goto $38
$11
  at 'org/apache/commons/logging/LogFactory.java' 1153
    @79 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
    if @79 !== null then goto $12 else goto $13
$12
  at 'org/apache/commons/logging/LogFactory.java' 1153
    @80 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
  at unknown location
    goto $14
$13
  at 'org/apache/commons/logging/LogFactory.java' 1153
    @81 := 'org.apache.commons.logging.LogFactory'
    @82 := invokeStatic `org.apache.commons.logging.LogFactory.class$(Ljava/lang/String;)Ljava/lang/Class;` @81
    field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory := @82 as `Ljava/lang/Class;`
    goto $14
$14
    @83 := phi @80 from $12, @82 from $13
  at 'org/apache/commons/logging/LogFactory.java' 1153
    @84 := invoke `java.lang.Class.isAssignableFrom(Ljava/lang/Class;)Z` @83, @76
  at unknown location
    @83 := nullCheck @83
  at 'org/apache/commons/logging/LogFactory.java' 1153
    if @84 != 0 then goto $10 else goto $15
$15
  at 'org/apache/commons/logging/LogFactory.java' 1154
    @85 := new org.apache.commons.logging.LogConfigurationException
    @86 := 'The chosen LogFactory implementation does not extend LogFactory. Please check your configuration.'
    invoke `org.apache.commons.logging.LogConfigurationException.(Ljava/lang/String;Ljava/lang/Throwable;)V` @85, @86, @e_1
    return @85
$16
  at 'org/apache/commons/logging/LogFactory.java' 1077
    @implementsLogFactory := invokeStatic `org.apache.commons.logging.LogFactory.implementsLogFactory(Ljava/lang/Class;)Z` @48
  at 'org/apache/commons/logging/LogFactory.java' 1084
    nop
    @msg := new java.lang.StringBuffer
    invoke `java.lang.StringBuffer.()V` @msg
  at 'org/apache/commons/logging/LogFactory.java' 1085
    nop
    @52 := 'The application has specified that a custom LogFactory implementation '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @52
  at 'org/apache/commons/logging/LogFactory.java' 1086
    @53 := 'should be used but Class \''
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @53
  at 'org/apache/commons/logging/LogFactory.java' 1087
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @factoryClass
  at 'org/apache/commons/logging/LogFactory.java' 1088
    @54 := '\' cannot be converted to \''
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @54
  at 'org/apache/commons/logging/LogFactory.java' 1089
    @55 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
    if @55 !== null then goto $17 else goto $18
    catch java.lang.Exception goto $7
$17
  at 'org/apache/commons/logging/LogFactory.java' 1089
    @56 := field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory as `Ljava/lang/Class;`
  at unknown location
    goto $19
    catch java.lang.Exception goto $7
$18
  at 'org/apache/commons/logging/LogFactory.java' 1089
    @57 := 'org.apache.commons.logging.LogFactory'
    @58 := invokeStatic `org.apache.commons.logging.LogFactory.class$(Ljava/lang/String;)Ljava/lang/Class;` @57
    field org.apache.commons.logging.LogFactory.class$org$apache$commons$logging$LogFactory := @58 as `Ljava/lang/Class;`
    goto $19
    catch java.lang.Exception goto $7
$19
    @59 := phi @56 from $17, @58 from $18
  at 'org/apache/commons/logging/LogFactory.java' 1089
    @60 := invoke `java.lang.Class.getName()Ljava/lang/String;` @59
  at unknown location
    @59 := nullCheck @59
  at 'org/apache/commons/logging/LogFactory.java' 1089
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @60
  at 'org/apache/commons/logging/LogFactory.java' 1090
    @61 := '\'. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @61
  at 'org/apache/commons/logging/LogFactory.java' 1091
    if @implementsLogFactory == 0 then goto $20 else goto $21
    catch java.lang.Exception goto $7
$20
  at 'org/apache/commons/logging/LogFactory.java' 1100
    @62 := 'Please check the custom implementation. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @62
  at unknown location
    goto $22
    catch java.lang.Exception goto $7
$21
  at 'org/apache/commons/logging/LogFactory.java' 1092
    @63 := 'The conflict is caused by the presence of multiple LogFactory classes '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @63
  at 'org/apache/commons/logging/LogFactory.java' 1093
    @64 := 'in incompatible classloaders. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @64
  at 'org/apache/commons/logging/LogFactory.java' 1094
    @65 := 'Background can be found in http://commons.apache.org/logging/tech.html. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @65
  at 'org/apache/commons/logging/LogFactory.java' 1095
    @66 := 'If you have not explicitly specified a custom LogFactory then it is likely '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @66
  at 'org/apache/commons/logging/LogFactory.java' 1096
    @67 := 'that the container has set one without your knowledge. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @67
  at 'org/apache/commons/logging/LogFactory.java' 1097
    @68 := 'In this case, consider using the commons-logging-adapters.jar file or '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @68
  at 'org/apache/commons/logging/LogFactory.java' 1098
    @69 := 'specifying the standard LogFactory from the command line. '
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @69
    goto $22
    catch java.lang.Exception goto $7
$22
  at 'org/apache/commons/logging/LogFactory.java' 1102
    @70 := 'Help can be found @http://commons.apache.org/logging/troubleshooting.html.'
    invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @msg, @70
  at 'org/apache/commons/logging/LogFactory.java' 1104
    @71 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
    if @71 == 0 then goto $23 else goto $24
    catch java.lang.Exception goto $7
$23
  at 'org/apache/commons/logging/LogFactory.java' 1108
    @72 := new java.lang.ClassCastException
    @73 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @msg
    invoke `java.lang.ClassCastException.(Ljava/lang/String;)V` @72, @73
    throw @72
    catch java.lang.Exception goto $7
$24
  at 'org/apache/commons/logging/LogFactory.java' 1105
    @74 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @msg
    invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @74
  at unknown location
    goto $23
    catch java.lang.Exception goto $7
$25
  at 'org/apache/commons/logging/LogFactory.java' 1123
    goto $2
    catch java.lang.Exception goto $7
$26
  at 'org/apache/commons/logging/LogFactory.java' 1062
    @34 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
    if @34 == 0 then goto $27 else goto $28
    catch java.lang.Exception goto $7
$27
  at 'org/apache/commons/logging/LogFactory.java' 1067
    throw @e
    catch java.lang.Exception goto $7
$28
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @35 := new java.lang.StringBuffer
    invoke `java.lang.StringBuffer.()V` @35
    @36 := 'Class \''
    @37 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @35, @36
    @38 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @37, @factoryClass
  at unknown location
    @37 := nullCheck @37
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @39 := '\' cannot be loaded'
    @40 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @38, @39
  at unknown location
    @38 := nullCheck @38
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @41 := ' via classloader '
    @42 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @40, @41
  at unknown location
    @40 := nullCheck @40
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @43 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader
    @44 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @42, @43
  at unknown location
    @42 := nullCheck @42
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @45 := ' - it depends on some other class that cannot be found.'
    @46 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @44, @45
  at unknown location
    @44 := nullCheck @44
  at 'org/apache/commons/logging/LogFactory.java' 1063
    @47 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @46
  at unknown location
    @46 := nullCheck @46
  at 'org/apache/commons/logging/LogFactory.java' 1063
    invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @47
  at unknown location
    goto $27
    catch java.lang.Exception goto $7
$29
  at 'org/apache/commons/logging/LogFactory.java' 1123
    goto $2
    catch java.lang.Exception goto $7
$30
  at 'org/apache/commons/logging/LogFactory.java' 1052
    @21 := invokeStatic `org.apache.commons.logging.LogFactory.isDiagnosticsEnabled()Z`
    if @21 == 0 then goto $31 else goto $32
    catch java.lang.Exception goto $7
$31
  at 'org/apache/commons/logging/LogFactory.java' 1056
    throw @ex
    catch java.lang.Exception goto $7
$32
  at 'org/apache/commons/logging/LogFactory.java' 1053
    @22 := new java.lang.StringBuffer
    invoke `java.lang.StringBuffer.()V` @22
    @23 := 'Unable to locate any class called \''
    @24 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @22, @23
    @25 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @24, @factoryClass
  at unknown location
    @24 := nullCheck @24
  at 'org/apache/commons/logging/LogFactory.java' 1053
    @26 := '\' via classloader '
    @27 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @25, @26
  at unknown location
    @25 := nullCheck @25
  at 'org/apache/commons/logging/LogFactory.java' 1053
    @28 := invokeStatic `org.apache.commons.logging.LogFactory.objectId(Ljava/lang/Object;)Ljava/lang/String;` @classLoader
    @29 := invoke `java.lang.StringBuffer.append(Ljava/lang/String;)Ljava/lang/StringBuffer;` @27, @28
  at unknown location
    @27 := nullCheck @27
  at 'org/apache/commons/logging/LogFactory.java' 1053
    @30 := invoke `java.lang.StringBuffer.toString()Ljava/lang/String;` @29
  at unknown location
    @29 := nullCheck @29
  at 'org/apache/commons/logging/LogFactory.java' 1053
    invokeStatic `org.apache.commons.logging.LogFactory.logDiagnostic(Ljava/lang/String;)V` @30
  at unknown location
    goto $31
    catch java.lang.Exception goto $7
$33
    @e := exception
    @32 := phi @logFactoryClass from $3, @17 from $3
  at 'org/apache/commons/logging/LogFactory.java' 1060
    nop
    @33 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
    if @classLoader !==@33 then goto $25 else goto $26
    catch java.lang.Exception goto $7
$34
    @48 := phi @logFactoryClass from $3, @17 from $3
  at 'org/apache/commons/logging/LogFactory.java' 1071
    nop
    @49 := field org.apache.commons.logging.LogFactory.thisClassLoader as `Ljava/lang/ClassLoader;`
    if @classLoader !==@49 then goto $2 else goto $16
    catch java.lang.Exception goto $7
$35
  at 'org/apache/commons/logging/LogFactory.java' 1014
    nop
    if @classLoader === null then goto $2 else goto $3
    catch java.lang.Exception goto $7
$36
  at 'org/apache/commons/logging/LogFactory.java' 1147
    return @8
$37
  at 'org/apache/commons/logging/LogConfigurationException.java' 55
    @90 := invokeVirtual `java.lang.Throwable.toString()Ljava/lang/String;` @e_1
  at unknown location
    goto $39
$38
  at 'org/apache/commons/logging/LogConfigurationException.java' 55
    @91 := null
    goto $39
$39
    @92 := phi @90 from $37, @91 from $38
  at 'org/apache/commons/logging/LogConfigurationException.java' 55
    invoke `org.apache.commons.logging.LogConfigurationException.(Ljava/lang/String;Ljava/lang/Throwable;)V` @78, @92, @e_1
  at 'org/apache/commons/logging/LogFactory.java' 1158
    return @78



Unexpected error occurred: java.lang.AssertionError: Variable used before definition: @17 at $3

This may happen if you have logger implementation like this:

pom:

Solution:

TeaVM has its own logging mechanism which logs not only on console, but also on browser Developer Console like javascript’s console.log() :

Make sure to remove any dependencies that depends on apache commons-logging (e.g. htmlunit ). To make sure run:

mvn dependency:tree

in project directory. This should display a list of all library dependencies throughout entire project like this:

Get rid of any dependency that relies on apache commons-logging as TeaVM has very little support of external libraries:

Add following dependencies for logging:

Also make sure to set javascript optimization level to SIMPLE instead of FULL which might cause longer build-time and unintended failed built msg, in pom.xml:

In java class:
Demo Code: Download

Running sample:

run: mvn clean package

open: target/teavm-logging-demo-1.0-SNAPSHOT/index.html in browser.