Apache Maven Assembly Plugin not working with OSGi bundles

前端 未结 1 1620
广开言路
广开言路 2020-12-10 23:24

I have a Maven OSGi multi-module project. The project runs perfectly well when the OSGi picks the module jars from the individual project modules. (view 1.1.B be

1条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 00:09

    I had to do a lot to get your sample to duplicate the question.

    First off your reactor order is wrong in the parent. That is why you have to do mvn install all the time.

    
        OSGiDmHelloWorldProvider
        OSGiDmHelloWorldConsumer
        main
        dist
    
    

    Next, if you define a dependency (e.g. JUnit) in the parent you don't need to redfine it in the children.

    Next, it is conventional to put the parent tag at the top of the pom.

    I don't see a reason to have your child modules have a different version to the parent so I removed the tag so they all have 1.0-SNAPSHOT from the parent.

    Next, you have the wrong group id in the OSGiDmHelloWorldProvider dependency (it should be rev).

        
            rev
            OSGiDmHelloWorldProvider
            1.0-SNAPSHOT
        
    

    In the main module you have a dependency that isn't in the reactor. I am guessing this is just an oversight of the sample.

        
            rev
            core
            1.0-SNAPSHOT
        
    

    After all that, mvn clean package -DskipTests=true works.

    You have a hard-coded string in your Main class that obviously doesn't work for me. (You also might want to look at the free IDEA Community instead of Eclipse!)

    String baseDir = "D:/standAloneDev/java/workingDir/Sample Projects/Eclipse/Gen/OSGiDmHelloWorld/dist/target/dist-1.0-SNAPSHOT-bin/plugins/";
    

    You should make this relative. e.g.

    File baseDir = new File("dist/target/dist-1.0-SNAPSHOT-bin/plugins/");
    String baseDirPath = baseDir.getAbsolutePath();
    
    loadScrBundle(framework);
    
    File provider = new File(baseDirPath, "OSGiDmHelloWorldProvider-1.0-SNAPSHOT.jar");
    File consumer = new File(baseDirPath, "OSGiDmHelloWorldConsumer-1.0-SNAPSHOT.jar");
    
    framework.getBundleContext().installBundle(provider.toURI().toString());
    framework.getBundleContext().installBundle(consumer.toURI().toString());
    

    Anyway, after getting it going I noticed the following javadoc on bundle.getSymbolicName().

    Returns the symbolic name of this bundle as specified by its Bundle-SymbolicName manifest header. The bundle symbolic name should be based on the reverse domain name naming convention like that used for java packages.
    

    So in the MANIFEST.MF of org.apache.felix.scr-1.6.2.jar you have

    Bundle-Name: Apache Felix Declarative Services
    Bundle-SymbolicName: org.apache.felix.scr
    

    You don't have this in yours as you are not creating a manifest and adding it to a jar.

    You need to add an execution phase and tell the jar plugin to use the manifest:

            
                maven-jar-plugin
                
                    
                        ${project.build.outputDirectory}/META-INF/MANIFEST.MF
                    
                
            
            
                org.apache.felix
                maven-bundle-plugin
                
                    
                        bundle-manifest
                        process-classes
                        
                            manifest
                        
                    
                
                true
                
                    
                        OSGiDmHelloWorldProvider
                        com.bw.osgi.provider.able
                        com.bw.osgi.provider.ProviderActivator
                        Baptiste Wicht
                    
                
            
    

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