2

What options do I need to add to the maven build or the java runtime to access the internal sun.security classes? There is Java code from Akamai in an OSGI bundle needs access to internal sun.security classes. The Apache Felix console gives errors for the OSGI bundle:

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
...

I looked at this article about using internal sun classes but it only refers to javac. My maven build starts like:

<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>
  ...
Community
  • 1
  • 1
Michael Shopsin
  • 2,055
  • 2
  • 24
  • 43

2 Answers2

24

I agree with stjohnroe that using VM-specific classes is usually bad, but sometimes you have to (for instance, as you are currently in a transition phase). If you want to do so, you can add

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

to the framework properties. If you use the standard Felix launcher, you can edit conf/config.properties for that.

Angelo van der Sijpt
  • 3,611
  • 18
  • 24
1

All of these are non public API classes and cannot be relied upon to be present in all jre distributions. I believe that they are all present sun distributions, but not in IBM distributions etc. Try running against a Sun distribution, but this looks like a case of building against undocumented features, a big no no.

stjohnroe
  • 3,168
  • 1
  • 27
  • 27
  • 1
    Akamai's code uses some old libraries that call internal sun.* classes. I already spent some time and found out about the JRE differences the hard way (MacOS X vs Linux). – Michael Shopsin Dec 16 '10 at 15:23
  • I'm going to remove the offending code from the OSGI bundle and put it in a standalone service until I can get rid of it. – Michael Shopsin Dec 16 '10 at 16:03