简体   繁体   English

Wildfly 21:可启动 JAR 找不到 H2 JDBC 驱动程序/数据源类

[英]Wildfly 21: bootable JAR can't find H2 JDBC driver/datasource classes

I'm deploying a bootable JAR on Wildfly 21.0.1.Final.我正在 Wildfly 21.0.1.Final 上部署可启动的 JAR。 The JAR is built with the wildfly-jar-maven-plugin. JAR 是使用 wildfly-jar-maven-plugin 构建的。 Here is the plugin configuration:这是插件配置:

<plugin>
  <groupId>org.wildfly.plugins</groupId>
  <artifactId>wildfly-jar-maven-plugin</artifactId>
  <configuration>
    <feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#21.0.0.Final
    </feature-pack-location>
    <layers>
       <layer>jaxrs-server</layer>
       <layer>management</layer>
       <layer>observability</layer>
       <layer>microprofile-openapi</layer>
       <layer>h2-driver</layer>
       <layer>h2-datasource</layer>
     </layers>
     <excluded-layers>
       <layer>deployment-scanner</layer>
     </excluded-layers>
   </configuration>
   ...
 </plugin>

Running the bootable JAR I get the exception below:运行可启动 JAR 我得到以下异常:

java -jar -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.http.port=8080 -Djboss.management.http.port=9990 customers/target/customers-bootable.jar 
14:04:58,500 INFO  [org.wildfly.jar] (main) WFLYJAR0007: Installed server and application in /tmp/wildfly-bootable-server15172013110481762654, took 1035ms
14:04:58,607 INFO  [org.wildfly.jar] (main) WFLYJAR0008: Server options: [--read-only-server-config=standalone.xml]
14:04:58,653 INFO  [org.jboss.msc] (main) JBoss MSC version 1.4.12.Final
14:04:58,658 INFO  [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final
14:04:58,730 INFO  [org.jboss.as] (MSC service thread 1-1) WFLYSRV0049: WildFly Full 21.0.0.Final (WildFly Core 13.0.1.Final) starting
14:04:59,134 INFO  [org.wildfly.security] (ServerService Thread Pool -- 14) ELY00001: WildFly Elytron version 1.13.1.Final
14:04:59,476 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
14:04:59,487 INFO  [org.xnio] (MSC service thread 1-2) XNIO version 3.8.2.Final
14:04:59,493 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.8.2.Final
14:04:59,504 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) WFLYCLINF0001: Activating Infinispan subsystem.
14:04:59,514 INFO  [org.wildfly.extension.microprofile.config.smallrye._private] (ServerService Thread Pool -- 37) WFLYCONF0001: Activating WildFly MicroProfile Config Subsystem
14:04:59,516 INFO  [org.jboss.as.jaxrs] (ServerService Thread Pool -- 33) WFLYRS0016: RESTEasy version 3.13.2.Final
14:04:59,517 INFO  [org.jboss.as.connector] (MSC service thread 1-3) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.23.Final)
14:04:59,521 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 42) WFLYNAM0001: Activating Naming Subsystem
14:04:59,519 INFO  [org.wildfly.extension.microprofile.openapi.smallrye] (ServerService Thread Pool -- 40) WFLYMPOAI0001: Activating Eclipse MicroProfile OpenAPI Subsystem
14:04:59,522 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 32) WFLYIO001: Worker 'default' has auto-configured to 24 IO threads with 192 max task threads based on your 12 available processors
14:04:59,520 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 45) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.               
14:04:59,524 INFO  [org.wildfly.extension.microprofile.health.smallrye] (ServerService Thread Pool -- 38) WFLYHEALTH0001: Activating Eclipse MicroProfile Health Subsystem
14:04:59,521 INFO  [org.wildfly.extension.microprofile.opentracing] (ServerService Thread Pool -- 41) WFLYTRACEXT0001: Activating MicroProfile OpenTracing Subsystem
14:04:59,537 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
14:04:59,542 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
14:04:59,545 INFO  [org.jboss.as.naming] (MSC service thread 1-7) WFLYNAM0003: Starting Naming Service
14:04:59,546 INFO  [org.wildfly.extension.microprofile.metrics.smallrye] (ServerService Thread Pool -- 39) WFLYMETRICS0001: Activating Eclipse MicroProfile Metrics Subsystem
14:04:59,549 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0003: Undertow 2.2.2.Final starting
14:04:59,555 INFO  [org.jboss.remoting] (MSC service thread 1-3) JBoss Remoting version 5.0.19.Final
14:04:59,611 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0012: Started server default-server.
14:04:59,612 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0018: Host default-host starting
14:04:59,635 WARN  [org.jboss.as.domain.http.api.undertow] (MSC service thread 1-3) WFLYDMHTTP0003: Unable to load console module for slot main, disabling console                                                                                                                                      
14:04:59,641 INFO  [org.jboss.as.patching] (MSC service thread 1-6) WFLYPAT0050: WildFly Full cumulative patch ID is: base, one-off patches include: none
14:04:59,646 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on [0:0:0:0:0:0:0:0]:8080
14:04:59,654 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-5) WFLYDM0111: Keystore /tmp/wildfly-bootable-server15172013110481762654/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost                                                                                                                                               
14:04:59,662 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "customers.war" (runtime-name: "ROOT.war")
14:04:59,743 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
14:05:01,202 INFO  [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read persistence.xml for customers
14:05:01,324 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment ROOT.war
14:05:01,536 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 6.0.21.Final
14:05:01,706 INFO  [io.jaegertracing.internal.JaegerTracer] (MSC service thread 1-1) No shutdown hook registered: Please call close() manually on application shutdown.
14:05:01,721 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."ROOT.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."ROOT.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "ROOT.war"                                                                                                                                       
...
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: org.h2.jdbcx.JdbcDataSource from [Module "deployment.ROOT.war" from Service Module Loader]   

The class org.h2.jdbcx.JdbcDataSource isn't found obviously.显然没有找到 class org.h2.jdbcx.JdbcDataSource。 However, looking in the bootable JAR I see that in the modules directory:但是,查看可启动 JAR 我在模块目录中看到:

[![modules][1]][1] [![模块][1]][1]

So, as shown above, the modules directory contains a module named "com.h2database.h2" and here is the content of the associated module.xml file:因此,如上所示,modules 目录包含一个名为“com.h2database.h2”的模块,这里是关联 module.xml 文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<module name="com.h2database.h2" xmlns="urn:jboss:module:1.5">
  <resources>
    <resource-root path="h2-1.4.197.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
  </dependencies>
</module>

And here is the content of the h2-1.4.197.jar archive:这是 h2-1.4.197.jar 存档的内容:

[![h2][2]][2] [![h2][2]][2]

Accordingly, the Wildfly server has a module named "com.h2database.h2" containing the required "org.h2.jdbcx.JdbcDtaSource" class.因此,Wildfly 服务器有一个名为“com.h2database.h2”的模块,其中包含所需的“org.h2.jdbcx.JdbcDtaSource”class。

So why does the CNFE is raised?那么为什么要提高CNFE呢? Last but not least, here is the datasource definition:最后但同样重要的是,这里是数据源定义:

@Singleton
@DataSourceDefinition(
  name = "java:jboss/datasources/ExampleDS",
  className = "org.h2.jdbcx.JdbcDataSource",
  url = "jdbc:h2:mem:customers",
  user = "sa",
  password = "sa",
  databaseName = "customers")
public class DatasourceProducer
{
  @Resource(lookup = "java:jboss/datasources/ExampleDS")
  private DataSource ds;

  @Produces
  public DataSource getDatasource()
  {
    return ds;
  }
}

And the persistence.xml file:和persistence.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="customers" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
    <properties>
      <property name="wildfly.jpa.twophasebootstrap" value="false" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.format_sql" value="true"/>
      <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>
</persistence>       

Could someone please shed some light here on this issue as I'm stuck since a couple of days:-(有人可以在这里阐明这个问题,因为我被困了几天:-(

Many thanks in advance.提前谢谢了。

Kind regards,亲切的问候,

Seymour [1]: https://i.stack.imgur.com/fUBOc.png [2]: https://i.stack.imgur.com/mHaGb.png西摩 [1]: https://i.stack.imgur.com/fUBOc.png [2]: https://i.stack.imgur.com/mHaGb.png

Answering my own question.回答我自己的问题。 It appears that simply defining the h2 dependency as follows:看来,只需将 h2 依赖项定义如下:

  <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
  </dependency>

instead of:代替:

  <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>test</scope>
  </dependency>

solves the problem.解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM