views:

24

answers:

3

I have written an application that use a third party library. I have then packaged this as an executable jar using the maven-assembly-plugin (producing a jar with all dependencies including some of the third-party jars).

Next I need to add this jar to a PDE project so it can be launched from eclipse. But to make this work I need to add some of the thirs-party dependencies to my PDE project which is already located in the packaged jar. So I get duplicated dependencies. Any ideas on how to avoid this? Or suggestion to documentation that describes how this is done properly?

A: 

I think it is just plain bad practice to include the other jars in your jar. But if you want to keep it that way, how about creating two jars from one build: a full one with dependencies, and a simple one to use in PDE (just use multiple executions in the assembly plugin)

seanizer
A: 

You should build a jar, that's an OSGi bundle: so it contains the required manifest.mf with a plug-in id and a version number (this does not change the fact, that the jar remains executable). Be careful to add the export-packages option to make the code available for other plug-ins/bundles as well.

After that you could install this jar into the target platform used by the PDE project (search for Target platform in the preferences), so it becomes available for other plug-ins by the ID (you could add it as a dependency).

This way, if at least one plug-in needs your jar, it gets loaded, but will not get loaded several times.

Zoltán Ujhelyi
A: 

I am now using the maven-bundle-plugin:

      <plugin>
          <groupId>org.apache.felix</groupId>
          <artifactId>maven-bundle-plugin</artifactId>
          <version>1.4.0</version>
          <extensions>true</extensions>
          <configuration>
              <instructions>
                  <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
                  <Bundle-Name>${pom.name}</Bundle-Name>
                  <Bundle-Version>${pom.version}</Bundle-Version>
                  <Bundle-Activator>org.wso2.mbp.sample01.Activator</Bundle-Activator>
                  <Private-Package>org.wso2.mbp.sample01</Private-Package>
              </instructions>
          </configuration>
      </plugin> 

http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

to build a bundle. But how do I use the bundle plugin so it creates the MANIFEST file for the jar build with the maven-assembly-plugin, which I use like:

    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <appendAssemblyId>true</appendAssemblyId>
      <finalName>myApp</finalName>

      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>         
      <archive>
        <manifest>
          <mainClass>com.TestMain</mainClass>                     
          <packageName>com.</packageName>
        </manifest>
      </archive>    
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>assembly</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
tul