正如中提到的奥伯利斯的回答在您链接到的问题中,您需要建立一个系统包片段,它公开了,即出口,sun.misc
包裹。我不知道还有什么其他办法。然而,这比预期的要容易。
您可以通过创建 OSGi 来做到这一点MANIFEST.MF
导出 sun.misc,然后将其捆绑到片段中。这是通过 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>
<groupId>your.group</groupId>
<version>1.0.0</version>
<artifactId>your.group.fragment.sun.misc</artifactId>
<packaging>jar</packaging>
<name>System Bundle Fragment exporting sun.misc</name>
<description>This bundle extends the System Bundle export list with the sun.misc package such that OSGi bundles may refer to Sun's misc implementation without the OSGi framework itself to provide it in a non-portable way.</description>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<forceCreation>true</forceCreation>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Export-Package>sun.misc</Export-Package>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<instructions>
<Bundle-Category>your.group</Bundle-Category>
<Fragment-Host>system.bundle; extension:=framework</Fragment-Host>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run mvn clean install
在此 POM 上。现在您需要使片段可供第谷使用,即您需要通过 p2 软件站点使其可用。
值得庆幸的是,有一个很棒的 Maven 插件可以帮助解决这个问题:reficio 的 p2-maven-plugin。您可以使用它基本上将任何 mavenized JAR 打包到 OSGi 包中,然后通过 p2 站点提供它。
如下设置相应的 POM。
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sun-misc-p2</groupId>
<artifactId>site</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<!-- specify your depencies here -->
<!-- groupId:artifactId:version -->
<artifact><id>com.lmax:disruptor:3.3.2</id></artifact>
<artifact><id>your.group:your.group.fragment.sun.misc:1.0.0</id></artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>${basedir}/target/repository/</webAppSourceDirectory>
<webApp>
<contextPath>/site</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</pluginRepository>
</pluginRepositories>
</project>
Note我使用这个插件来提供 LMAX Disruptor(版本 3.3.2,撰写本文时的最新版本,值得庆幸的是可以从 Maven Central 获得)。
Run mvn p2:site
在 POM 上。这将创建一个 p2 站点,其中包含sun.misc
片段在{project-folder}/target/repository
.
这个 p2 存储库 - 以及随之而来的sun.misc
片段 - 现在可以添加到您的目标平台,因此可以在您的第谷构建中使用。
这应该可以解决这个问题,并且 - 如果“[您]可以通过任何可能的方式添加[您的]插件本身”来回答您的问题 - 这是唯一可能的方法(我知道)。
来源也可在https://github.com/newcodeontheblock/eclipse-rcp-with-async-logging。整个过程也有更详细的描述这是我的关于在 Eclipse RCP 中使用异步 Log4j 2 记录器的博客文章.