Search code examples
osgiosgi-bundlemaven-bundle-plugin

src is used instead of target for bundling package


When I run command "mvn package" on my project, resource files like persistence.xml, persistence.xml.dev, persistence.xml.qa etc..from src/main/resources/META-INF are packed in the bundle. I need help to make mvn-bundle-plugin to look at target folder instead of src folder because my target folder will have only one resource file persistence.xml. My pom mave-bundle-plugin is below

<plugin>
                      <groupId>org.apache.felix</groupId>
                      <artifactId>maven-bundle-plugin</artifactId>
                      <extensions>true</extensions>
                      <executions>
                          <execution>
                              <id>bundle</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>bundle</goal>
                              </goals>
                          </execution>
                      </executions>
                      <configuration>
                          <instructions>
                              <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                              <Bundle-Classpath>.</Bundle-Classpath>
                              <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                              <Embed-Dependency>
                                  my-project-api
                              </Embed-Dependency>
                              <Export-Package></Export-Package>
                              <Import-Package>
                                  javax.ws.rs;version="[2.0,3)",
                                  javax.ws.rs.core;version="[2.0,3)",
                                  *</Import-Package>
                         </instructions>
                      </configuration>
</plugin>

Solution

  • Following Link explains how to include resources in the final bundle under topic "Instructions -> Include Resource". http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

    Following the documentation, I added Included-Resource tag in instructions in pom xml as below and it worked i.e. the plugin packed the resource file from target folder.

    <instructions>
       <Include-Resource>
             META-INF/persistence.properties=target/classes/META-INF/persistence.properties
       </Include-Resource>
       <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
       <Bundle-Classpath>.</Bundle-Classpath>
       <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
       <Embed-Dependency>
               my-project-api
        </Embed-Dependency>
        <Export-Package></Export-Package>
        <Import-Package>
              javax.ws.rs;version="[2.0,3)",
              javax.ws.rs.core;version="[2.0,3)",
         *</Import-Package>
    </instructions>