切换到 Java-11 后第谷无法解析 javax.rmi

Tycho can't resolve javax.rmi after switching to Java-11

我正在尝试将我们的遗留多模块项目切换到 Java-11,但第谷抱怨缺少依赖项 在我的 pom 文件中,我将 JDK 版本添加为 11。这是 pom

的一部分
...
 <properties>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <jdk-version>11</jdk-version>
    <!-- Plugins tycho version -->
    <tycho.version>1.7.0</tycho.version>
...
 </properties>
<build>
...
<plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-plugin</artifactId>
        <version>${tycho.version}</version>
        <configuration>
          <source>${jdk-version}</source>
          <target>${jdk-version}</target>
        </configuration>
      </plugin>
...
</build>

这是我的 META-INF/MANIFEST.MF 文件

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Meta-Persistence: META-INF/openjpa_persistence_product.xml
Bundle-Name: JPA
Bundle-SymbolicName: com.XXX.jpa
Bundle-Version: 2.1.2
Bundle-Vendor: XXX
Bundle-RequiredExecutionEnvironment: JavaSE-11
Eclipse-ExtensibleAPI: true
Import-Package: com.XXX.config,
 com.XXX.core,
 com.XXX.core.util.logging,
 com.XXX.sql,
 javax.persistence,
 javax.persistence.criteria,
 javax.persistence.metamodel,
 org.apache.openjpa.persistence,
 org.apache.openjpa.util,
 org.osgi.framework,
 org.osgi.service.component,
 org.osgi.service.jdbc,
 org.osgi.service.jndi,
 org.osgi.service.jpa,
 org.slf4j
Export-Package: com.XXX.jpa,
 com.XXX.jpa.concurrent,
 com.XXX.jpa.util
Service-Component: OSGI-INF/*.xml
Bundle-ActivationPolicy: lazy

执行mvn clean install后我收到了

ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: com.XXX.jpa 2.1.2
[ERROR]   Missing requirement: org.apache.openjpa 3.0.0 requires 'java.package; javax.rmi 0.0.0' but it could not be found
[ERROR]   Cannot satisfy dependency: com.XXX.jpa 2.1.2 depends on: java.package; org.apache.openjpa.persistence 0.0.0

我试过的

  1. 将版本添加到 org.apache.openjpa.persistence,org.apache.openjpa.util 到 MANIFEST.MF
  2. 将 javax.rmi 添加到 MANIFEST.MF
  3. 的导入包部分

但结果总是一样的 - 第谷对 javax.rmi 包裹的投诉

更新 嗨@howlger!感谢您的帮助,但现在我又遇到了一个问题

  1. 我为 javax.rmi
  2. 创建了 bunlde
  <parent>
    <groupId>com.XXX</groupId>
    <artifactId>bundle.platform</artifactId>
    <version>2.1.2</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  
  <!-- This bundle was added because in Java-11 javax.rmi package was removed from the standard library -->
  <groupId>com.XXX</groupId>
  <artifactId>com.XXX.javax.rmi</artifactId>
  <version>1.0.6.Final</version>
  <packaging>bundle</packaging>
  <name>Java RMI API Bundle</name>
  
  <dependencies>
    <dependency>
      <groupId>org.jboss.spec.javax.rmi</groupId>
      <artifactId>jboss-rmi-api_1.0_spec</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>
              *;version="${project.version}"
            </Export-Package>
            <Import-Package>
              *
            </Import-Package>
            <Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
            <Bundle-SymbolicName>
              ${project.artifactId}
            </Bundle-SymbolicName>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

并部署到我们的工件,但遗憾的是无法将此包添加到 p2 功能

我将它添加为主 pom 文件的依赖项,该文件将 p2 存储库创建为

 <dependencies>
 <!-- com.XXX.javax.rmi -->
    <dependency>
      <groupId>org.jboss.spec.javax.rmi</groupId>
      <artifactId>jboss-rmi-api_1.0_spec</artifactId>
      <version>${javax.rmi.version}</version>
    </dependency>    
    <dependency>
      <groupId>org.jboss.spec.javax.rmi</groupId>
      <artifactId>jboss-rmi-api_1.0_spec</artifactId>
      <version>${javax.rmi.version}</version>
      <classifier>sources</classifier>
    </dependency>
 </dependencies> 

但是当我尝试将该包作为插件添加到平台功能时

<plugin
        id="com.XXX.javax.rmi"
        download-size="0"
        install-size="0"
        version="0.0.0"
        unpack="false"/>

我收到了:

[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: com.XXX.repository 2.1.2
[ERROR]   Missing requirement: com.XXX.bundle.platform.feature.feature.group 2.1.2 requires 'org.eclipse.equinox.p2.iu; com.navteq.javax.rmi 0.0.0' but it could not be found
[ERROR]   Cannot satisfy dependency: com.navteq.phoenix.repository 2.1.2 depends on: org.eclipse.equinox.p2.iu; com.navteq.phoenix.bundle.platform.feature.feature.group [2.1.2,2.1.3)
[ERROR]

我做错了什么?

更新2 本期主要有2个问题

  1. 创建 p2 存储库的主 pom 文件中的依赖项不正确 - 它应该具有与创建 bandle 的 pom 中相同的 groupId、artifactId、版本
<dependencies>
 <!-- com.XXX.javax.rmi -->
    <dependency>
      <groupId>com.XXX</groupId>
      <artifactId>com.XXX.javax.rmi</artifactId>
      <version>1.0.6.Final</version>
    </dependency>
 </dependencies>
  1. 应该将 sun.refelection 的导入添加到创建 bundle
  2. 的 pom 文件中
<configuration>
  <instructions>
    <Export-Package>
      *;version="${project.version}"
    </Export-Package>
    <Import-Package>
      sun.reflect;resolution:=optional
    </Import-Package>
    <Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
    <Bundle-SymbolicName>
      ${project.artifactId}
    </Bundle-SymbolicName>
  </instructions>
</configuration>

javax.rmi package was contain in the system library (in Java 9 and 10 in the module java.corba) until it was removed in Java 11 by JEP 320.

对于 Java 11 或更高版本,您需要 添加包含包 javax.rmi 的 plugin/bundle 到您的目标platform 因为它是您拥有的 org.apache.openjpa plugin/bundle 所必需的。或者可能有更新版本的 org.apache.openjpa 包含 javax.rmi 包或不再需要它。