英文:
How to cure ASM issues with TomEE 8.x, Hibernate 5.4 and Java 8?
问题
根据这个页面,TomEE 8.0 兼容 Java 8:http://tomee.apache.org/master/docs/java-compatibility.html
然而,我在使用 TomEE 和 Hibernate 与 Java 8 设置项目时遇到了一些问题。
我正在使用 Maven 原型 org.apache.openejb.maven:tomee-webapp-archetype 版本 1.7.1 创建项目。我的项目 SDK 是一个简单的 JDK 1.8.0_221。
一切进行得很顺利。运行 mvn package
和 mvn tomee:run
启动了一个工作正常的示例应用程序。
现在我进入 pom.xml 文件,添加了 Hibernate 依赖:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.14.Final</version>
</dependency>
在没有对项目进行更多修改的情况下,mvn package
仍然正常工作。但是当启动应用程序时,我遇到了以下问题:
[INFO] Scanning for projects...
...
根据我的研究,这似乎是一个关于 ASM4 和 Java 8 的 bug,可以在这里找到:https://stackoverflow.com/questions/25611851/java-lang-illegalargumentexception-at-org-apache-xbean-asm4-classreader-init 。但是我正在使用的最新 TomEE 版本依赖于 ASM5,应该支持 Java 8。为什么只有在添加 Hibernate 依赖时才出现问题?而 Hibernate 5.4 似乎与 Java 8 兼容。
英文:
According to this page, TomEE 8.0 is compatible with Java 8: http://tomee.apache.org/master/docs/java-compatibility.html
However, I am getting some issue setting up a project with TomEE and Hibernate with java 8.
I creating a project from the Maven archetype org.apache.openejb.maven:tomee-webapp-archetype version 1.7.1. My project SDK is a simple JDK 1.8.0_221.
Everything is going fine. Running the mvn package
and mvn tomee:run
starts a sample app application which is working perfectly.
Now I go to my pom.xml file and I add the Hibernate dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.14.Final</version>
</dependency>
with no more modification on the project. mvn package
still works fine. But when starting the application I get the following:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:TomEETest >------------------------
[INFO] Building TomEETest TomEE Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- tomee-maven-plugin:1.7.1:run (default-cli) @ TomEETest ---
[INFO] TomEE was unzipped in '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee'
[INFO] Removed not mandatory default webapps
[INFO] Installed '/Users/bcassistat/IdeaProjetcs/TomEETest/target/TomEETest-1.0-SNAPSHOT.war' in /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war
[INFO] Running 'org.apache.openejb.maven.plugin.run'. Configured TomEE in plugin is localhost:8080 (plugin shutdown port is 8005 and https port is 8443)
Started server process on port: 8080
May 04, 2020 5:47:47 PM org.apache.catalina.core.AprLifecycleListener init
INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/bcassistat/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
May 04, 2020 5:47:47 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-bio-8080"]
May 04, 2020 5:47:47 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["ajp-bio-8009"]
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'tomee.remote.support=true'
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.jdbc.datasource-creator=org.apache.tomee.jdbc.TomEEDataSourceCreator'
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: OpenEJB http://openejb.apache.org/
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Startup: Mon May 04 17:47:48 EDT 2020
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Copyright 1999-2013 (C) Apache OpenEJB Project, All Rights Reserved.
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Version: 4.7.1
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Build date: 20140912
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: Build time: 01:43
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: openejb.home = /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance <init>
INFOS: openejb.base = /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee
May 04, 2020 5:47:48 PM org.apache.openejb.cdi.CdiBuilder initializeOWB
INFOS: Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@587c290d
May 04, 2020 5:47:48 PM org.apache.openejb.cdi.CdiBuilder initializeOWB
INFOS: Succeeded in installing singleton service
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory init
INFOS: openejb configuration file is '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/conf/tomee.xml'
[INFO] Waiting for command: [quit, exit, reload]
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory configureService
INFOS: Configuring Service(id=Tomcat Security Service, type=SecurityService, provider-id=Tomcat Security Service)
May 04, 2020 5:47:48 PM org.apache.openejb.config.ConfigurationFactory configureService
INFOS: Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.system.apps=false'
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.deployments.classpath=false'
May 04, 2020 5:47:48 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating TransactionManager(id=Default Transaction Manager)
May 04, 2020 5:47:49 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating SecurityService(id=Tomcat Security Service)
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS: ** Bound Services **
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager printRow
INFOS: NAME IP PORT
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS: -------
May 04, 2020 5:47:49 PM org.apache.openejb.server.SimpleServiceManager start
INFOS: Ready!
May 04, 2020 5:47:49 PM org.apache.catalina.startup.Catalina load
INFOS: Initialization processed in 2002 ms
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.OpenEJBNamingContextListener bindResource
INFOS: Importing a Tomcat Resource with id 'UserDatabase' of type 'org.apache.catalina.UserDatabase'.
May 04, 2020 5:47:49 PM org.apache.openejb.assembler.classic.Assembler createRecipe
INFOS: Creating Resource(id=UserDatabase)
May 04, 2020 5:47:49 PM org.apache.catalina.core.StandardService startInternal
INFOS: Démarrage du service Catalina
May 04, 2020 5:47:49 PM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet Engine: Apache Tomcat (TomEE)/7.0.55 (1.7.1)
May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
INFOS: Déploiement de l'archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l'application web
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFOS: ------------------------- localhost -> /
May 04, 2020 5:47:49 PM org.apache.openejb.util.JarExtractor extract
INFOS: Extracting jar: /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war
May 04, 2020 5:47:49 PM org.apache.openejb.util.JarExtractor extract
INFOS: Extracted path: /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT
May 04, 2020 5:47:49 PM org.apache.openejb.util.OptionsLog info
INFOS: Using 'openejb.session.manager=org.apache.tomee.catalina.session.QuickSessionManager'
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
AVERTISSEMENT: jar '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/javax.persistence-api-2.2.jar' contains offending class: javax.persistence.Entity. It will be ignored.
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
AVERTISSEMENT: jar '/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar' contains offending class: javax.transaction.Transaction. It will be ignored.
May 04, 2020 5:47:49 PM org.apache.catalina.core.ContainerBase addChildInternal
GRAVE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Unable to create annotation scanner for web module : null
at org.apache.tomee.catalina.TomcatWebAppBuilder.loadApplication(TomcatWebAppBuilder.java:2150)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1134)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: org.apache.openejb.OpenEJBException: Unable to create annotation scanner for web module : null
at org.apache.openejb.config.DeploymentLoader.addWebModule(DeploymentLoader.java:844)
at org.apache.openejb.config.DeploymentLoader.load(DeploymentLoader.java:216)
at org.apache.tomee.catalina.TomcatWebAppBuilder.loadApplication(TomcatWebAppBuilder.java:2148)
... 17 more
Caused by: java.lang.IllegalArgumentException
at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
at org.apache.xbean.asm5.ClassReader.<init>(Unknown Source)
at org.apache.xbean.finder.AnnotationFinder.readClassDef(AnnotationFinder.java:1148)
at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:139)
at org.apache.xbean.finder.AnnotationFinder.<init>(AnnotationFinder.java:152)
at org.apache.openejb.config.FinderFactory$OpenEJBAnnotationFinder.<init>(FinderFactory.java:514)
at org.apache.openejb.config.FinderFactory.newFinder(FinderFactory.java:259)
at org.apache.openejb.config.FinderFactory.create(FinderFactory.java:77)
at org.apache.openejb.config.FinderFactory.createFinder(FinderFactory.java:66)
at org.apache.openejb.config.DeploymentLoader.addWebModule(DeploymentLoader.java:836)
... 19 more
May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
GRAVE: Erreur lors du déploiement de l'archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l'application web
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
May 04, 2020 5:47:49 PM org.apache.catalina.startup.HostConfig deployWAR
INFOS: Deployment of web application archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war has finished in 474 ms
May 04, 2020 5:47:49 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-bio-8080"]
May 04, 2020 5:47:49 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
May 04, 2020 5:47:49 PM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 637 ms
According to my research, it looks like a bug with ASM4 with Java 8 found on this : https://stackoverflow.com/questions/25611851/java-lang-illegalargumentexception-at-org-apache-xbean-asm4-classreader-init . But the latest TomEE version I am using depends on ASM5 which should support Java 8. And why does the problem occurs only when adding the Hibernate dependency? And Hibernate 5.4 seems to be compatible with Java 8.
答案1
得分: 4
问题
版本为1.7.1
的TomEE Webapp Archetype将启动一个相当旧的TomEE实例(运行时环境),见:
> INFOS: 正在启动Servlet引擎:Apache Tomcat(TomEE)/7.0.55(1.7.1)
和
> INFOS: 构建日期:20140912
解决方案
相反,使用版本为8.0.x
的TomEE Webapp Archetype(最新版本:8.0.6)。这将修复ASM的问题,因为容器启动时的运行时依赖项将与Hibernate 5.4.x的依赖项匹配。
作为提醒:检查/验证每个Hibernate 5.4.x的(编译和)运行时依赖项是否在容器环境的/lib
目录中提供,或者打包在您的应用程序的.war
文件中。
英文:
Problem
TomEE Webapp Archetype in version 1.7.1
will start a (quite) old TomEE instance (runtime environment), see:
> INFOS: Starting Servlet Engine: Apache Tomcat (TomEE)/7.0.55 (1.7.1)
and
> INFOS: Build date: 20140912
Solution
Instead, use the TomEE Webapp Archetype in version 8.0.x
(latest: 8.0.6). This will fix the ASM situation as the runtime dependencies on container start-up will match those of Hibernate 5.4.x.
As a reminder: Check/verify every (compile and) runtime dependency of Hibernate 5.4.x is provided in the /lib
directory of the container environment, or bundled in the .war
file of your application.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论