Best way to convert existing java projects to osgi bundles

前端 未结 3 842
旧巷少年郎
旧巷少年郎 2021-02-14 22:44

We have lot of components out of which we want to modularize only a few to start with. Wondering what is the best way (in the context of my build environment) to create bundles

3条回答
  •  失恋的感觉
    2021-02-14 22:52

    Start by only changing the MANIFEST.MF entries such that all your artifacts become bundles - they obviously won't magically work but it's a good non-destructive first step.

    When using the maven-bundle-plugin ensure you set extensions and supportedProjectTypes as you may have problems with CI builds, Maven repos and m2e failing if the packaging type is bundle (see end).

    Test your riskiest/core external dependencies early on - for example if you're using JPA for persistence then ensure that the provider works in an OSGi environment with your domain bundle and JDBC driver.

    If you're migrating from Java EE/spring look at Karaf or Virgo. But if your components are for embedded systems or have no external dependencies the Felix or Equinox may be enough (though check out the pax-url project if that's the case).

    Might be worth editing your question to be a bit more specific about the domain/technologies?


    eclipse:eclipse only generates that when the project is first configured, m2e's lifecycle problems might be a bit of pain but it's far better than using the old eclipse plug.


    The following will add manifest entries to your existing artifacts without changing them in any other way. It tells the standard maven jar and war plugins to use the MANIFEST.MF generated by maven-bundle-plugin.

    Put this in the parent POM:

    
    
        org.apache.felix
        maven-bundle-plugin
        2.3.7
        true
        
            
                true
            
            
                jar
                war
            
            
                ${project.organization.name}
                ${project.organization.name}
                ${project.organization.url}
                ${project.description}
                ${bundle.doc.url}
                ${bundle.category}
                ${project.artifactId}
                ${project.version}
    
                *
                *
            
        
        
            
                bundle
                
                    manifest
                
                prepare-package
                true
            
        
    
    
    
        org.apache.maven.plugins
        maven-jar-plugin
        2.3.1
        
            
                ${project.build.outputDirectory}/META-INF/MANIFEST.MF
            
        
    
    
    
        maven-war-plugin
        2.1.1
        
            
                create-war
                package
                
                    war
                
                true
            
        
        
            
                ${project.build.outputDirectory}/META-INF/MANIFEST.MF
            
        
    
    
    

    Then in child POMs, you may simply do:

    
        
            
                org.apache.felix
                maven-bundle-plugin
            
            
            
                org.apache.maven.plugins
                maven-jar-plugin
            
        
    
    

提交回复
热议问题