unable to satisfy dependency from com.lmax.disruptor 3.2.0 to package sun.misc 0.0.0

前端 未结 1 1542
滥情空心
滥情空心 2021-01-15 02:08

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 e

1条回答
  •  死守一世寂寞
    2021-01-15 02:40

    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.

    
        4.0.0
          your.group
          1.0.0
    
        your.group.fragment.sun.misc
        jar
        System Bundle Fragment exporting sun.misc
    
        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.
    
        
            
                
                    maven-jar-plugin
                    
                        true
                        
                            ${project.build.outputDirectory}/META-INF/MANIFEST.MF
                            
                                sun.misc
                            
                        
                    
                
                
                    org.apache.felix
                    maven-bundle-plugin
                    2.5.4
                    
                        
                            bundle-manifest
                            process-classes
                            
                                manifest
                            
                        
                    
                    
                        
                            your.group
                            system.bundle; extension:=framework
                        
                    
                
    
            
        
    
    
    

    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.

    
      4.0.0
      sun-misc-p2
      site
      1.0.0
      pom
    
      
                
                    
                        org.reficio
                        p2-maven-plugin
                        1.1.1
                        
                            
                                default-cli
                                
                                    
                                        
                                        
                                        com.lmax:disruptor:3.3.2
                                        your.group:your.group.fragment.sun.misc:1.0.0
                                    
                                
                            
                        
                    
                    
                        org.mortbay.jetty
                        jetty-maven-plugin
                        8.1.5.v20120716
                        
                            10
                            ${basedir}/target/repository/
                            
                                /site
                            
                       
                    
                
            
            
                
                    reficio
                    http://repo.reficio.org/maven/
                
             
    
    

    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.

    0 讨论(0)
提交回复
热议问题