如oberlies' answer在您鏈接到的問題中提到,你需要建立一個系統綁定片段,這暴露,即出口,sun.misc
包。我不知道任何其他方式。但是,這比預期的更容易。
您可以通過創建導出sun.misc的OSGi MANIFEST.MF
來完成此操作,然後將其捆綁到一個片段中。這是通過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>
在此POM上運行mvn clean install
。現在您需要製作Tycho的碎片消耗品,即您需要通過p2軟件站點使其可用。
謝天謝地,有一個偉大的Maven插件可以幫助你:reficio's p2-maven-plugin。您可以使用它來基本上將任何maven化的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>
注意,我使用這個插件提供LMAX干擾器(版本3.3.2,最新一個在寫作的時候,是值得慶幸的是可以從Maven的中央)。在POM上運行mvn p2:site
。這將創建一個包含sun.misc
片段的p2網站,網址爲{project-folder}/target/repository
。
此p2存儲庫及其sun.misc
片段現在可以添加到您的目標平臺,因此可用於您的Tycho構建。
這應該解決它,並且 - 如果「有任何可能的方式可以添加到你的插件本身中」,這是唯一可行的方法。
該來源也可在https://github.com/newcodeontheblock/eclipse-rcp-with-async-logging。整個程序也在this - my - blog post about using async Log4j 2 loggers in an Eclipse RCP中有更詳細的描述。
該片段也可從Maven Central獲得:http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22net.sdruskat.fragment.sun.misc%22 –