5

I've generated an application using JHipster 7.0.0. It has "monolith" as applicationType, "postgressql" as prodDatabaseType and "h2Disk" as devDatabaseType.

When I run command line "./mwnw", the applications launches perfectly.

The problem comes when I try to debug the application in the VSCode IDE following these instructions:https://www.jhipster.tech/development/. I right-click the file of Application class (the one with @SpringBootApplication annotation), click "Debug Java" menu, and during the launch I get this exception:

2021-04-02 18:51:36.143 DEBUG 46054 --- [           main] br.gov.mypackage.config.WebConfigurer       : Initialize H2 console
2021-04-02 18:51:36.145  WARN 46054 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
2021-04-02 18:51:36.251 ERROR 46054 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
        at br.gov.ancine.JhipsterLearnApp.main(JhipsterLearnApp.java:69)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.createManager(UndertowServletWebServerFactory.java:345)
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:314)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159)
        ... 7 common frames omitted
Caused by: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
        at tech.jhipster.config.h2.H2ConfigurationHelper.initH2Console(H2ConfigurationHelper.java:128)
        at br.gov.ancine.config.WebConfigurer.initH2Console(WebConfigurer.java:119)
        at br.gov.ancine.config.WebConfigurer.onStartup(WebConfigurer.java:52)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:234)
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory$Initializer.onStartup(UndertowServletWebServerFactory.java:504)
        at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:204)
        at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
        at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
        at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
        ... 11 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.h2.server.web.WebServlet
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at tech.jhipster.config.h2.H2ConfigurationHelper.initH2Console(H2ConfigurationHelper.java:119)
        ... 20 common frames omitted

It looks like if VSCode doesn't include the h2database in the classpath.

Fabiano
  • 143
  • 9

2 Answers2

2

It might not be the perfect solution, but it should at least get you started. In your pom.xml file, in the dependencies section, change h2 scope, from test to compile.

<dependencies>
    ...
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>compile</scope>
    </dependency>
    ....
    <!-- jhipster-needle-maven-add-dependency -->
</dependencies>

Launch your debug session from VSCode and the previously missing h2 classes should be there (if you comment out the call to H2ConfigurationHelper.initH2Console you will see that some other h2 classes are missing). If you set scope back to test, it keeps running fine within VSCode.

0

Here is the answer:

  1. run at the root application folder:

    mvn spring-boot:run -D"spring-boot.run.jvmArguments"="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

https://stackoverflow.com/a/68069089/1184154

  1. run at vscode launch.json:

{ "version": "0.2.0", "configurations": [

{
  "type": "java",
  "name": "Debug (Launch)",
  "request": "launch",
  "mainClass": "",
  "args": ""
},
{
  "type": "java",
  "name": "Debug (Attach)",
  "request": "attach",
  "hostName": "localhost",
  "port": 8000
}

] }

https://stackoverflow.com/a/46841712/1184154

Renan Franca
  • 3,438
  • 1
  • 18
  • 17