I am developing an eclipse plugin which needs an com.lmax.disruptor.It imports sun.misc. I have this in my p2 repository but when I maven build my plugin I am getting this error "unable to satisfy dependency from com.lmax.disruptor 3.2.0 to package sun.misc 0.0.0."
I have gone through the sites Resolve a dependency on package sun.misc with Tycho they are saying to create a plugin fragment but when I tried to create it and added export page as sun.misc, It is throwing an error like "package sun.misc doesnot exsist in the plugin".
How can solve this issue please help me with this.? Instead of creating new plugin fragment,is there is any possible way i can add in my plugin itself ?
Thanks,
As mentioned in oberlies' answer in the question you link to, you need to build a system bundle fragment, which exposes, i.e., exports, the sun.misc
package. I don't know of any other way. However, this is easier than could be expected.
You do this by creating an OSGi MANIFEST.MF
that exports sun.misc, and then bundle it into a fragment. This is done via Maven as follows.
<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
on this POM. Now you need to make the fragment consumable for Tycho, i.e., you need to make it available via a p2 Software Site.
Thankfully there is a great Maven plugin which can help with that: reficio's p2-maven-plugin. You can use it to basically wrap any mavenized JAR into an OSGi bundle and then provide it via a p2 site.
Set up the respective POM as follows.
<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 that I use this plugin to provide the LMAX Disruptor (version 3.3.2, the latest one at the time of writing, is thankfully available from Maven Central).
Run mvn p2:site
on the POM. This will create a p2 site containing the sun.misc
fragment at {project-folder}/target/repository
.
This p2 repository - and with it the sun.misc
fragment - can now be added to your target platform, and hence used in your Tycho build.
This should fix it, and - to answer your question if "there is any possible way [you] can add in [your] plugin itself" - this is the only possible way to do it (I know of).
The sources are also available at https://github.com/newcodeontheblock/eclipse-rcp-with-async-logging. The whole procedure is also described in more detail in this - my - blog post about using async Log4j 2 loggers in an Eclipse RCP.