javamavenwso2osgimaven-bundle-plugin

WSO2 and creating deployable archive takes old properties from Maven


I have another problem with WSO2 ESB. I have created some Maven project. The project is included into Java Library Project from WSO2. In library project I set maven-bundle-plugin set in pom.xml. It creates MANIFEST correctly via Maven build, but Export Project as Deployable Archive creates MANIFEST.md with old properties (I think, MANIFEST with properties after creating fresh project through Eclipse (unchanged SymbolicName, no imports).

Maven Project with classes to bundle POM.xml

<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>com.coig.esb.osgi</groupId>
  <artifactId>emf</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>

  <name>emf</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
  <dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>javax.persistence-api</artifactId>
      <version>2.2</version>
  </dependency>

  </dependencies>
</project>

Then jar file from project above is imported to Java Library Project from WSO2.

Java Library Project POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.coig.esb.osgi.emf.EMFService</groupId>
  <artifactId>EMFService</artifactId>
  <version>1.0.0</version>
  <packaging>bundle</packaging>
  <name>EMFService</name>
  <description>EMFService</description>
  <properties>
    <CApp.type>lib/library/bundle</CApp.type>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.coig.esb.osgi</groupId>
      <artifactId>emf</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
      </releases>
      <id>wso2-nexus</id>
      <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
    </repository>
    <repository>
      <id>wso2-maven2-repository-1</id>
      <url>http://dist.wso2.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
      </releases>
      <id>wso2-nexus</id>
      <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
    </pluginRepository>
    <pluginRepository>
      <id>wso2-maven2-repository-1</id>
      <url>http://dist.wso2.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.4</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>com.coig.osgi.emf.providerservice</Bundle-SymbolicName>
            <Bundle-Name>EMFService</Bundle-Name>
            <Export-Package>com.coig.esb.osgi.emf,com.coig.esb.osgi.emf</Export-Package>
            <DynamicImport-Package>*</DynamicImport-Package>
            <Embed-Dependency>emf</Embed-Dependency>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <buildcommands />
          <projectnatures>
            <projectnature>org.wso2.developerstudio.eclipse.library.project.nature</projectnature>
          </projectnatures>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

MANIFEST.md from Export

Manifest-Version: 1.0
Bundle-SymbolicName: EMFService
Bundle-Name: EMFService
Bundle-Version: 1.0.0
Bundle-Description: EMFService
Export-Package: com.coig.esb.osgi.emf,
 com.coig.esb.osgi.emf
DynamicImport-Package: *

MANIFEST.md from Maven build

Manifest-Version: 1.0
Bundle-Description: EMFService
Bundle-SymbolicName: com.coig.osgi.emf.providerservice
Built-By: author
Bundle-ManifestVersion: 2
Bnd-LastModified: 1532429067922
Embed-Dependency: emf
Import-Package: javax.persistence;version="[2.2,3)"
DynamicImport-Package: *
Tool: Bnd-1.15.0
Export-Package: com.coig.esb.osgi.emf;uses:="javax.persistence",com.co
 ig.esb.osgi.emf
Bundle-Version: 1.0.0
Bundle-Name: EMFService
Bundle-ClassPath: .,emf-1.0.0.jar
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_172

When I've created Mediator project, set maven-bunlde-plugin to import my previously mentioned module, there is the same situation. Maven build creates correct MANIFEST.md, but Export Project as Deployable Archive creates MANIFEST.md with unchanged properties.

Could you provide me some remarks, how it should be set?


Solution

  • Looks like "Export Project As Deployable Archive" does not support Import-Package header in MANIFEST.MF. This file is built by MediatorExportHandler class which ignores this header.

    IJavaProject javaProject = JavaCore.create(project);
    
    List<String> exportPac =getExportPackages(javaProject);
    BundleManifest manifest = new BundleManifest();    
    manifest.setBundleName(project.getName());
    manifest.setBundleSymbolicName(project.getName());
    manifest.setBundleDescription(project.getName());
    manifest.setBundleVersion("2.0");
    manifest.setExportPackagesList(exportPac);
    [...]
    File manifestFile=new File(metainfPath,"MANIFEST.MF");
    FileUtils.createFile(manifestFile, manifest.toString());