java Glassfish 服务器不适用于 JDK 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13139794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:38:22  来源:igfitidea点击:

Glassfish server does not work with JDK 8

javaglassfishjava-8

提问by onsm7

I'm using jdk 8 with lambda in a web project with NetBeans, but when a deploy it to glassfish it shows me this error:

我在一个带有 NetBeans 的 Web 项目中使用带有 lambda 的 jdk 8,但是当将它部署到 glassfish 时,它显示了这个错误:

java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>

This is caused by lines of code that include lambda expression.

这是由包含 lambda 表达式的代码行引起的。

I tried changing the glassfish settings to work with jdk 8 but I have not gotten it to work.

我尝试更改 glassfish 设置以使用 jdk 8,但我还没有让它工作。

Is there any way to make it work?

有没有办法让它工作?

回答by Martin Andersson

I have observed all kinds of strange behavior using GlassFish 4 combined with JDK 8. It seems to be the case that when using new syntax introduced in Java 1.8, the class which uses the new features will trigger an ArrayIndexOutOfBoundsExceptionduring startup that reads something like this:

我观察到了结合使用 GlassFish 4 和 JDK 8 的各种奇怪行为。似乎是这样,当使用 Java 1.8 中引入的新语法时,使用新功能的类将ArrayIndexOutOfBoundsException在启动期间触发读取如下内容:

   Exception while visiting
 martinandersson/com/malivechat/ejb/events/EventService.class of size
 7094

 java.lang.ArrayIndexOutOfBoundsException: 25966
   at org.objectweb.asm.ClassReader.readClass(ClassReader.java:2015)
   at org.objectweb.asm.ClassReader.accept(ClassReader.java:469)
   at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
   at org.glassfish.hk2.classmodel.reflect.Parser.on(Parser.java:362)
   at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.handleEntry(ReadableArchiveScannerAdapter.java:165)
   at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.onSelectedEntries(ReadableArchiveScannerAdapter.java:127)
   at org.glassfish.hk2.classmodel.reflect.Parser.doJob(Parser.java:347)
   at org.glassfish.hk2.classmodel.reflect.Parser.access0(Parser.java:67)
   at org.glassfish.hk2.classmodel.reflect.Parser.call(Parser.java:306)
   at org.glassfish.hk2.classmodel.reflect.Parser.call(Parser.java:295)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:744)

Sometimes the class being examined by GlassFish survives the "crash" and can be used properly within the application, sometimes not. The crashed class will sometimes hinder your application from being deployed. GlassFish complain that the bean of the wanted type could not be found or instantiated. Sometimes, the crashing class will not hinder the deployment from succeeding but the class fails one way or another when he's used instead. For example, resources injected in the bean will fail and your application will inevitably throw a NullPointerException.

有时,GlassFish 正在检查的类会在“崩溃”中幸存下来并且可以在应用程序中正确使用,有时则不能。崩溃的类有时会阻碍您的应用程序的部署。GlassFish 抱怨无法找到或实例化所需类型的 bean。有时,崩溃的类不会阻碍部署的成功,但是当使用它时,类会以一种或另一种方式失败。例如,注入到 bean 中的资源将失败,您的应用程序将不可避免地抛出一个NullPointerException.

Except from the fact that GlassFish has a non-existent support of JDK 1.8, Java itself seem to crash for me every other time I try to build my project and a JavaFX application of mine sometimes black out and various components he's made of is extremely buggy too. So production code should definitely stay away from upgrading to Java 1.8 for a while.

除了 GlassFish 不支持 JDK 1.8 的事实之外,Java 本身似乎每隔一次我尝试构建我的项目时就会崩溃,我的 JavaFX 应用程序有时会停电,而且他制作的各种组件非常有缺陷也。因此,生产代码绝对应该暂时远离升级到 Java 1.8。

Update

更新

I'm also having serious problems with EclipseLink 2.5.2-M1. One entity class of mine worked perfectly in Java 1.7, then came the time when I added some neat JDK 8 syntax in it. After that, EclipseLink refused to let the entity class be a target for a JPA relationship. EclipseLink said that the entity class was a "non-entity" type. As soon as I rewrote the JDK 8 sugar into legacy 1.7 code all worked just fine again.

我也有EclipseLink 2.5.2-M1 的严重问题。我的一个实体类在 Java 1.7 中运行良好,然后我在其中添加了一些简洁的 JDK 8 语法。之后,EclipseLink 拒绝让实体类成为 JPA 关系的目标。EclipseLink 表示实体类是“非实体”类型。一旦我将 JDK 8 的糖改写成遗留的 1.7 代码,一切又都可以正常工作了。

Update 2014-07-03

更新 2014-07-03

GlassFish 4.0.1-b05has only one issue with Java 1.8 code: JPA entity classes. Meaning it is EclipseLinkthat are having the issues. But I can confirm that Java 1.8 code work in EJB:s and CDI managed beans.

GlassFish 4.0.1-b05 的Java 1.8 代码只有一个问题:JPA 实体类。这意味着EclipseLink有问题。但我可以确认 Java 1.8 代码在 EJB:s 和 CDI 托管 bean 中工作。

回答by Arun Gupta

I tried running GlassFish with JDK8 and could not start as well.

我尝试使用 JDK8 运行 GlassFish,但也无法启动。

Filed a JIRA issue GLASSFISH-19263for tracking purpose.

提交 JIRA 问题GLASSFISH-19263以进行跟踪。