【问题标题】:How to access the internal sun.security class from an OSGI bundle?如何从 OSGI 包访问内部 sun.security 类?
【发布时间】:2011-05-26 14:49:53
【问题描述】:

我需要向 maven 构建或 java 运行时添加哪些选项才能访问内部 sun.security 类?在 OSGI 包中有来自 Akamai 的 Java 代码需要访问内部 sun.security 类。 Apache Felix 控制台给出了 OSGI 包的错误:

sun.awt.image.codec -- Cannot be resolved
sun.io -- Cannot be resolved
sun.misc -- Cannot be resolved
sun.rmi.rmic -- Cannot be resolved
sun.security.action -- Cannot be resolved
sun.security.ec -- Cannot be resolved
sun.security.internal.interfaces -- Cannot be resolved
...

我查看了this article about using internal sun classes,但它仅指 javac。我的 Maven 构建开始如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>cdncache</artifactId>
  <packaging>bundle</packaging>
  <name>NCDN Cache</name>
  <description>Classes and interfaces to expire resource from the Akamai CDN cache [build:${build.number}]\
</description>
  <version>1.0-${build.number}</version>
  <properties>
    <!-- Skip tests, so maven execution is faster. -->
    <maven.test.skip>true</maven.test.skip>
    <file.encoding>utf-8</file.encoding>
  </properties>
  <build>
    <plugins>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.0.1</version>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Export-Package>
          com.nymag.akamai,
          com.akamai.*,
          ...
        </Export-Package>
        <Private-Package>
          org.apache.axis.*,
          ...
          sun.security,
          sun.security.ec,
        </Private-Package>
        <Bundle-Version>1.0</Bundle-Version>
        <Bundle-Activator>com.nymag.akamai.Activator</Bundle-Activator>
      </instructions>
    </configuration>
  </plugin>
  ...

【问题讨论】:

  • 感谢您的编辑,当我发布问题时,我仍在挖掘问题。

标签: maven osgi java apache-felix


【解决方案1】:

我同意 stjohnroe 的观点,即使用特定于 VM 的类通常不好,但有时您必须这样做(例如,因为您目前处于过渡阶段)。如果你想这样做,你可以添加

org.osgi.framework.system.packages.extra=sun.your.package.of.choice

到框架属性。如果您使用标准的 Felix 启动器,您可以为此编辑 conf/config.properties。

【讨论】:

  • 有趣的想法,所以可以强制 OSGI 允许内部类。
  • 安吉洛的回答是正确的。很遗憾你已经接受了错误的答案。
【解决方案2】:

所有这些都是非公共 API 类,不能依赖于所有 jre 发行版中的存在。我相信它们都是现有的 sun 发行版,但不在 IBM 发行版等中。尝试针对 Sun 发行版运行,但这看起来像是针对未记录的功能构建的情况,这是一个很大的禁忌。

【讨论】:

  • Akamai 的代码使用了一些调用内部 sun.* 类的旧库。我已经花了一些时间,并以艰难的方式发现了 JRE 的差异(MacOS X 与 Linux)。
  • 我将从 OSGI 包中删除有问题的代码并将其放入独立服务中,直到我可以摆脱它为止。
猜你喜欢
  • 2012-07-22
  • 1970-01-01
  • 2011-01-02
  • 2019-09-02
  • 2011-12-16
  • 2021-12-31
  • 1970-01-01
  • 2011-02-13
相关资源
最近更新 更多