使用 Java EE API 替换已弃用的 JPMS 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48204141/
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-08-12 02:47:45  来源:igfitidea点击:

Replacements for deprecated JPMS modules with Java EE APIs

javajakarta-eejava-9java-module

提问by Nicolai

Java 9 deprecated six modules that contain Java EE APIsand they are going to be removedsoon:

Java 9弃用了包含 Java EE API 的六个模块,它们很快被删除

  • java.activationwith javax.activationpackage
  • java.corbawith javax.activity, javax.rmi, javax.rmi.CORBA, and org.omg.*packages
  • java.transactionwith javax.transactionpackage
  • java.xml.bindwith all javax.xml.bind.*packages
  • java.xml.wswith javax.jws, javax.jws.soap, javax.xml.soap, and all javax.xml.ws.*packages
  • java.xml.ws.annotationwith javax.annotationpackage
  • java.activationjavax.activation
  • java.corbawith javax.activity, javax.rmi, javax.rmi.CORBA, 和org.omg.*
  • 带有javax.transaction包的java.transaction
  • java.xml.bind与所有javax.xml.bind.*
  • java.xml.wsjavax.jwsjavax.jws.soapjavax.xml.soap,和所有javax.xml.ws.*
  • 带有javax.annotation包的java.xml.ws.annotation

Which maintained third-party artifacts provide those APIs? It doesn't matter how well they provide those APIs or which other features they have to offer - all that matters is, are they a drop-in replacement for these modules/packages?

哪些维护的第三方工件提供了这些 API?他们提供这些 API 的程度如何或他们必须提供哪些其他功能并不重要——重要的是,它们是否是这些模块/包的直接替代品?

To make it easier to collect knoweldge, I answered with what I know so far and made the answer a community wiki. I hope people will extend it instead of writing their own answers.

为了更容易收集知识,我用我目前所知道的来回答,并将答案设为社区维基。我希望人们能扩展它而不是自己写答案。



Before you vote to close:

在您投票关闭之前:

  • Yes, there are already some questions on individual modules and an answer to this question would of course duplicate that information. But AFAIK there is no single point to learn about all of these, which I think has a lot of value.
  • Questions asking for library recommendations are usually considered off-topic, because "they tend to attract opinionated answers and spam", but I don't think that applies here. The set of valid libraries is clearly delineated: They have to implement a specific standard. Beyond that nothing else matters, so I don't see much risk for opinion and spam.
  • 是的,已经有一些关于单个模块的问题,这个问题的答案当然会重复该信息。但是 AFAIK 没有一点可以了解所有这些,我认为这很有价值。
  • 要求图书馆推荐的问题通常被认为是题外话,因为“它们往往会吸引自以为是的答案和垃圾邮件”,但我认为这不适用于这里。一组有效的库被清楚地描述:它们必须实现特定的标准。除此之外,其他一切都不重要,所以我认为意见和垃圾邮件的风险不大。

采纳答案by Nicolai

Instead of using the deprecated Java EE modules, use the following artifacts.

不要使用已弃用的 Java EE 模块,而是使用以下工件。

JAF (java.activation)

JAF ( java.activation)

JavaBeans Activation Framework is a standalone technology (available on Maven Central):

JavaBeans Activation Framework 是一项独立技术(可在 Maven Central 上获得):

<dependency>
    <groupId>com.sun.activation</groupId>
    <artifactId>javax.activation</artifactId>
    <version>1.2.0</version>
</dependency>

(Source)

来源

CORBA (java.corba)

CORBA ( java.corba)

From JEP 320:

JEP 320 开始

There will not be a standalone version of CORBA unless third parties take over maintenance of the CORBA APIs, ORB implementation, CosNaming provider, etc. Third party maintenance is possible because the Java SE Platform endorses independent implementations of CORBA. In contrast, the API for RMI-IIOP is defined and implemented solely within Java SE. There will not be a standalone version of RMI-IIOP unless a dedicated JSR is started to maintain it, or stewardship of the API is taken over by the Eclipse Foundation (the transition of stewardship of Java EE from the JCP to the Eclipse Foundation includes GlassFishand its implementation of CORBA and RMI-IIOP).

除非第三方接管 CORBA API、ORB 实现、CosNaming 提供者等的维护,否则不会有独立版本的 CORBA。因为 Java SE 平台认可 CORBA 的独立实现,所以第三方维护是可能的。相比之下,RMI-IIOP 的 API 仅在 Java SE 中定义和实现。除非有专门的 JSR 来维护它,否则不会有独立版本的 RMI-IIOP,或者 API 的管理权由 Eclipse 基金会接管(Java EE 的管理权从 JCP 到 Eclipse 基金会的过渡包括GlassFish及其对 CORBA 和 RMI-IIOP 的实现)。

JTA (java.transaction)

JTA ( java.transaction)

Stand alone version:

单机版:

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.2</version>
</dependency>

(Source; take a look for how to use 1.2and the upcoming 1.3on class and module path.)

来源;看看如何使用1.2以及即将到来1.3的类和模块路径。)

JAXB (java.xml.bind)

JAXB ( java.xml.bind)

Since Java EE was rebranded to Jakarta EE, JAXB is now provided by new artifacts:

由于 Java EE更名为 Jakarta EE,因此 JAXB 现在由新工件提供:

<!-- API -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>

<!-- Runtime -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

The old artifacts jaxb-coreand jaxb-implare not recommendedto use because they contain split packages.

不推荐使用旧工件jaxb-core,因为它们包含拆分包。jaxb-impl

JAXB Reference Implementation page.

JAXB 参考实现页面

schemagenand xjccan be download there too as part of a standalone JAXB distribution.

schemagenxjc可以作为独立 JAXB 发行版的一部分在那里下载。

See also linked answer.

另请参阅链接答案

JAX-WS (java.xml.ws)

JAX-WS ( java.xml.ws)

Reference implementation:

参考实现:

<!-- API -->
<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>2.3.2</version>
</dependency>

<!-- Runtime -->
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.2</version>
</dependency>

Standalone distribution download(contains wsgenand wsimport).

独立分发下载(包含wsgenwsimport)。

Common Annotations (java.xml.ws.annotation)

公共注解(java.xml.ws.annotation

Java Commons Annotations(available on Maven Central):

Java Commons Annotations(可在 Maven Central 上获得):

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.1</version>
</dependency>

(Source)

来源

回答by bourgesl

JAXB (java.xml.bind) for JDK9

JDK9 的 JAXB (java.xml.bind)

Working perfectly in my desktop applications on jdk9/10 EA

在 jdk9/10 EA 上的桌面应用程序中完美运行

<properties>
    <jaxb-api.version>2.3.0</jaxb-api.version>
</properties>

<!-- JAXB 2.3.0 for jdk9+ -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb-api.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>${jaxb-api.version}</version>
</dependency>
<!-- JAXB needs javax.activation module (jdk9) -->
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
</dependency>

回答by theNikki1

It seems that jaxws-ri depends transitively from commonj.sdo:commonj.sdo:jar:2.1.1.v201112051852 which apparently can be found from repository http://download.eclipse.org/rt/eclipselink/maven.repo

似乎 jaxws-ri 依赖于 commonj.sdo:commonj.sdo:jar:2.1.1.v201112051852 显然可以从存储库http://download.eclipse.org/rt/eclipselink/maven.repo 中找到

回答by virgo47

I needed to replace JAX-WS (java.xml.ws) and JAXB (java.xml.bind) for my Spring Boot 2 based application and ended up with these JARs (Gradle build):

我需要为基于 Spring Boot 2 的应用程序替换 JAX-WS (java.xml.ws) 和 JAXB (java.xml.bind) 并最终得到这些 JAR (Gradle build):

// replacements for deprecated JDK module java.xml.ws
runtimeOnly 'javax.xml.ws:jaxws-api:2.3.0' // javax.xml.ws.* classes
runtimeOnly 'javax.jws:jsr181-api:1.0-MR1' // for javax.jws.* classes

// replacement for deprecated JDK module java.xml.bind
runtimeOnly 'javax.xml.bind:jaxb-api'
runtimeOnly 'org.glassfish.jaxb:jaxb-runtime:2.3.0.1'
runtimeOnly 'org.glassfish:javax.json:1.1.2'
runtimeOnly 'org.eclipse:yasson:1.0.1'

(You may need compileor other scope, runtimeOnlywas enough for us.)

(您可能需要compile或其他范围,runtimeOnly对我们来说已经足够了。)

I noticed that https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-coreis described as "Old" and using this answerwent for org.glassfishbased stuff that brought in org.eclipse.yassonas well.

我注意到https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core被描述为“旧”,并且使用这个答案也适用于org.glassfish引入的基础内容org.eclipse.yasson

Now it's really messy situation, it works, but how should anyone be sure it's the best replacement, right?

现在情况真的很混乱,它可以工作,但是任何人应该如何确定它是最好的替代品,对吗?

回答by George

I found the easiest path to get around the JAXB parts of these issues was to use dependency management in my root pom or in my bom:

我发现解决这些问题的 JAXB 部分的最简单方法是在我的根 pom 或我的 bom 中使用依赖项管理:

    <project ...>
      <dependencyManagement>
        <dependencies>
          <!-- ... -->
          <!-- Gone from jvm in java11 -->
          <dependency>
          <groupId>com.sun.xml.bind</groupId>
          <artifactId>jaxb-ri</artifactId>
          <version>2.4.0-b180830.0438</version>
          <scope>import</scope>
          <type>pom</type>
        </dependency>
        <!-- ... -->
      </dependencies>
    </dependencyManagement>
    </project>

And in the modules that fail compilation on jdk11:

在 jdk11 上编译失败的模块中:

    <!-- ... -->
    <dependencies>
      <!-- Gone from jvm in java11 -->
      <dependency>
         <groupId>javax.xml.bind</groupId>
         <artifactId>jaxb-api</artifactId>
      </dependency>
      <dependency>
         <groupId>com.sun.xml.bind</groupId>
         <artifactId>jaxb-impl</artifactId>
         <scope>runtime</scope>
      </dependency>
      <dependency>
         <groupId>org.glassfish.jaxb</groupId>
         <artifactId>jaxb-runtime</artifactId>
         <scope>runtime</scope>
      </dependency>
      <!-- ... -->
    </dependencies>  
    <!-- ... -->

Also, updating the version of org.jvnet.jaxb2.maven2:maven-jaxb2-pluginto 0.14.0 solved all the jaxb generation issues for me.

此外,将 的版本更新org.jvnet.jaxb2.maven2:maven-jaxb2-plugin为 0.14.0 为我解决了所有 jaxb 生成问题。

回答by paul-emil

Just a minor variation (improvement) on the above answers --- exemplified here for JAXB only. One can add the dependencies with the runtimescope and only if this is effectively needed (i.e. when building for running in a JRE with version >= 9 --- here v11 is exemplified):

只是对上述答案的一个小变化(改进)——这里仅以 JAXB 为例。可以添加具有runtime范围的依赖项,并且只有在有效需要时才可以添加(即在构建以在版本 >= 9 的 JRE 中运行时 --- 此处以 v11 为例):

<profile>
        <id>when-on-jdk-11</id>
        <activation>
            <jdk>11</jdk>
        </activation>

        <properties>
            <!-- missing artefacts version properties -->
            <jaxb-api.version>2.3.1</jaxb-api.version>
            <jaxb-impl.version>2.3.2</jaxb-impl.version> <!-- one might let it the same with the jaxb-api.version -->
        </properties>

        <dependencies>
            <!-- runtime dependencies to avoid JAXB related CNF exceptions when running on Java 11 (e.g.: ClassNotFoundException: javax.xml.bind.annotation.XmlType) -->
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>${jaxb-api.version}</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
                <version>${jaxb-impl.version}</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </profile>

回答by Des Albert

I have experimented with most of the suggestions described above using JDK 11.0.3 and have been not been successful. The only solution that I eventually found to work is the following. Perhaps there are other options that also work but it appears that the selection of version is critical. For example, changing com.sun.xml.ws:rt to 2.3.2 causes module javax.jws to no long be available.

我已经使用 JDK 11.0.3 对上述大部分建议进行了试验,但都没有成功。我最终发现可行的唯一解决方案如下。也许还有其他选项也可以使用,但似乎版本的选择至关重要。例如,将 com.sun.xml.ws:rt 更改为 2.3.2 会导致模块 javax.jws 不再可用。

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.4.0-b180830.0438</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>rt</artifactId>
        <version>2.3.1</version>
    </dependency>