如何解决TomEE 8.x、Hibernate 5.4和Java 8的ASM问题?

huangapple go评论74阅读模式
英文:

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 packagemvn 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:

&lt;dependency&gt;
  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
  &lt;version&gt;5.4.14.Final&lt;/version&gt;
&lt;/dependency&gt;

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] -----------------------&lt; org.example:TomEETest &gt;------------------------
[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 &#39;/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee&#39;
[INFO] Removed not mandatory default webapps
[INFO] Installed &#39;/Users/bcassistat/IdeaProjetcs/TomEETest/target/TomEETest-1.0-SNAPSHOT.war&#39; in /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war
[INFO] Running &#39;org.apache.openejb.maven.plugin.run&#39;. 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 [&quot;http-bio-8080&quot;]
May 04, 2020 5:47:47 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler [&quot;ajp-bio-8009&quot;]
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using &#39;tomee.remote.support=true&#39;
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using &#39;openejb.jdbc.datasource-creator=org.apache.tomee.jdbc.TomEEDataSourceCreator&#39;
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: OpenEJB http://openejb.apache.org/
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: Startup: Mon May 04 17:47:48 EDT 2020
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: Copyright 1999-2013 (C) Apache OpenEJB Project, All Rights Reserved.
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: Version: 4.7.1
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: Build date: 20140912
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: Build time: 01:43
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: ********************************************************************************
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
INFOS: openejb.home = /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee
May 04, 2020 5:47:48 PM org.apache.openejb.OpenEJB$Instance &lt;init&gt;
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 &#39;/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/conf/tomee.xml&#39;
[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 &#39;openejb.system.apps=false&#39;
May 04, 2020 5:47:48 PM org.apache.openejb.util.OptionsLog info
INFOS: Using &#39;openejb.deployments.classpath=false&#39;
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 &#39;UserDatabase&#39; of type &#39;org.apache.catalina.UserDatabase&#39;.
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&#233;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&#233;ploiement de l&#39;archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l&#39;application web
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFOS: ------------------------- localhost -&gt; /
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 &#39;openejb.session.manager=org.apache.tomee.catalina.session.QuickSessionManager&#39;
May 04, 2020 5:47:49 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
AVERTISSEMENT: jar &#39;/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/javax.persistence-api-2.2.jar&#39; 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 &#39;/Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar&#39; 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.&lt;init&gt;(Unknown Source)
at org.apache.xbean.asm5.ClassReader.&lt;init&gt;(Unknown Source)
at org.apache.xbean.asm5.ClassReader.&lt;init&gt;(Unknown Source)
at org.apache.xbean.finder.AnnotationFinder.readClassDef(AnnotationFinder.java:1148)
at org.apache.xbean.finder.AnnotationFinder.&lt;init&gt;(AnnotationFinder.java:139)
at org.apache.xbean.finder.AnnotationFinder.&lt;init&gt;(AnnotationFinder.java:152)
at org.apache.openejb.config.FinderFactory$OpenEJBAnnotationFinder.&lt;init&gt;(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&#233;ploiement de l&#39;archive /Users/bcassistat/IdeaProjetcs/TomEETest/target/apache-tomee/webapps/ROOT.war de l&#39;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 [&quot;http-bio-8080&quot;]
May 04, 2020 5:47:49 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler [&quot;ajp-bio-8009&quot;]
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.1TomEE Webapp Archetype将启动一个相当旧的TomEE实例(运行时环境),见:

> INFOS: 正在启动Servlet引擎:Apache Tomcat(TomEE)/7.0.55(1.7.1)

> INFOS: 构建日期:20140912

解决方案

相反,使用版本为8.0.xTomEE 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.

huangapple
  • 本文由 发表于 2020年5月5日 06:11:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/61602487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定