Wildfly Swarm (Thorntail) 无法启动 - InvocationTargetException
Wildfly Swarm (Thorntail) cannot start - InvocationTargetException
我的 JavaEE 应用程序有问题,我尝试创建将自动部署的应用程序,所以我选择了 Thorntail,但在使用 mvn thorntail:run
启动它后,我收到此错误消息
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
at org.wildfly.swarm.bootstrap.MainInvoker.main(MainInvoker.java:106)
Caused by: java.lang.RuntimeException: org.jboss.shrinkwrap.api.importer.ArchiveImportException: Could not obtain ZIP File from File
at org.wildfly.swarm.Swarm.initializeConfigView(Swarm.java:635)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:254)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:192)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:179)
at org.wildfly.swarm.Swarm.main(Swarm.java:739)
... 6 more
Caused by: org.jboss.shrinkwrap.api.importer.ArchiveImportException: Could not obtain ZIP File from File
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:178)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:157)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:49)
at org.wildfly.swarm.Swarm.initializeConfigFiltersClassPath(Swarm.java:693)
at org.wildfly.swarm.Swarm.initializeConfigFilters(Swarm.java:643)
at org.wildfly.swarm.Swarm.initializeConfigView(Swarm.java:632)
... 10 more
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.zip.ZipFile.<init>(ZipFile.java:169)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:176)
... 15 more
我的 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.edu</groupId>
<artifactId>money-transfer-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javamoney.version>1.3</javamoney.version>
<h2.version>1.4.197</h2.version>
<junit.version>5.1.0</junit.version>
<junit.surefire.provider>1.3.0</junit.surefire.provider>
<assertj.version>3.11.1</assertj.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.war.plugin.version>3.2.2</maven.war.plugin.version>
<maven.surefire.plugin.version>2.22.0</maven.surefire.plugin.version>
<version.thorntail>2.2.0.Final</version.thorntail>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>${javamoney.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>ejb</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jpa</artifactId>
</dependency>
</dependencies>
<build>
<finalName>money-transfer-app</finalName>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
一开始以为是Java10版本的问题,降到8版本后问题依旧。预先感谢您的所有提示
编辑。
在 mvn clean package
和 java -jar target/money-transfer-app-thorntail.jar
之后还有另一个错误
2018-09-10 19:37:05,388 ERROR [stderr] (main) org.wildfly.swarm.container.DeploymentException: org.wildfly.swarm.container.DeploymentException: THORN0004: Deployment failed: {"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.undefined"],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"money-transfer-app.war#h2DataBase\" is missing [jboss.naming.context.java.undefined]","jboss.persistenceunit.\"money-transfer-app.war#h2DataBase\".__FIRST_PHASE__ is missing [jboss.naming.context.java.undefined]"]}
我的 persistence.xml
文件是问题的根源,我已经配置了 H2 数据源,现在应用程序运行正常
persistence.xml
文件的先前版本
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="h2DataBase" transaction-type="JTA">
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
修改后
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="test" transaction-type="JTA">
<class>model.Account</class>
<class>model.Owner</class>
<class>model.payments.Payment</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
persistence.xml 很可能不是问题的原因。
如果我对 Thorntail 的理解正确,它会从您的 Maven 存储库中提取依赖项,并期望它们已经存在。如果由于某种原因它们还不存在(例如,您的 pom 缺少 Thorntail 需要的依赖项),它在读取 jar 文件时只会失败。如果是这样的话,那么也许可以改进错误处理。
我的 JavaEE 应用程序有问题,我尝试创建将自动部署的应用程序,所以我选择了 Thorntail,但在使用 mvn thorntail:run
启动它后,我收到此错误消息
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
at org.wildfly.swarm.bootstrap.MainInvoker.main(MainInvoker.java:106)
Caused by: java.lang.RuntimeException: org.jboss.shrinkwrap.api.importer.ArchiveImportException: Could not obtain ZIP File from File
at org.wildfly.swarm.Swarm.initializeConfigView(Swarm.java:635)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:254)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:192)
at org.wildfly.swarm.Swarm.<init>(Swarm.java:179)
at org.wildfly.swarm.Swarm.main(Swarm.java:739)
... 6 more
Caused by: org.jboss.shrinkwrap.api.importer.ArchiveImportException: Could not obtain ZIP File from File
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:178)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:157)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:49)
at org.wildfly.swarm.Swarm.initializeConfigFiltersClassPath(Swarm.java:693)
at org.wildfly.swarm.Swarm.initializeConfigFilters(Swarm.java:643)
at org.wildfly.swarm.Swarm.initializeConfigView(Swarm.java:632)
... 10 more
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.zip.ZipFile.<init>(ZipFile.java:169)
at org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl.importFrom(ZipImporterImpl.java:176)
... 15 more
我的 pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.edu</groupId>
<artifactId>money-transfer-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javamoney.version>1.3</javamoney.version>
<h2.version>1.4.197</h2.version>
<junit.version>5.1.0</junit.version>
<junit.surefire.provider>1.3.0</junit.surefire.provider>
<assertj.version>3.11.1</assertj.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.war.plugin.version>3.2.2</maven.war.plugin.version>
<maven.surefire.plugin.version>2.22.0</maven.surefire.plugin.version>
<version.thorntail>2.2.0.Final</version.thorntail>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>${javamoney.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>ejb</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jpa</artifactId>
</dependency>
</dependencies>
<build>
<finalName>money-transfer-app</finalName>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
一开始以为是Java10版本的问题,降到8版本后问题依旧。预先感谢您的所有提示
编辑。
在 mvn clean package
和 java -jar target/money-transfer-app-thorntail.jar
之后还有另一个错误
2018-09-10 19:37:05,388 ERROR [stderr] (main) org.wildfly.swarm.container.DeploymentException: org.wildfly.swarm.container.DeploymentException: THORN0004: Deployment failed: {"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.undefined"],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"money-transfer-app.war#h2DataBase\" is missing [jboss.naming.context.java.undefined]","jboss.persistenceunit.\"money-transfer-app.war#h2DataBase\".__FIRST_PHASE__ is missing [jboss.naming.context.java.undefined]"]}
我的 persistence.xml
文件是问题的根源,我已经配置了 H2 数据源,现在应用程序运行正常
persistence.xml
文件的先前版本
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="h2DataBase" transaction-type="JTA">
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
修改后
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="test" transaction-type="JTA">
<class>model.Account</class>
<class>model.Owner</class>
<class>model.payments.Payment</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
persistence.xml 很可能不是问题的原因。
如果我对 Thorntail 的理解正确,它会从您的 Maven 存储库中提取依赖项,并期望它们已经存在。如果由于某种原因它们还不存在(例如,您的 pom 缺少 Thorntail 需要的依赖项),它在读取 jar 文件时只会失败。如果是这样的话,那么也许可以改进错误处理。