如何从OSGI包中访问内部sun.security类?

Mic*_*sin 2 java osgi maven apache-felix

我需要将哪些选项添加到maven构建或java运行时才能访问内部sun.security类?来自Akamai的Java代码在OSGI包中需要访问内部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
...
Run Code Online (Sandbox Code Playgroud)

我看了这篇关于使用内部sun类的文章,但它只引用了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>
  ...
Run Code Online (Sandbox Code Playgroud)

Ang*_*jpt 23

我同意stjohnroe使用特定于VM的类通常是坏的,但有时您必须(例如,因为您当前处于过渡阶段).如果您想这样做,可以添加

org.osgi.framework.system.packages.extra=sun.your.package.of.choice
Run Code Online (Sandbox Code Playgroud)

到框架属性.如果您使用标准的Felix启动器,则可以对其进行编辑conf/config.properties.

  • Angelo的回答是正确的.你已经接受了错误的答案,这是一种耻辱. (3认同)