Friday, April 27, 2012

Usefull eclipse application startup parameters


Mainly because I do not remember extacly all small things I put them here...


Program arguments :
  • -consoleLog
  • -clean

VM arguments :
  • -Dosgi.requiredJavaVersion=1.5
  • -Dosgi.clean=true
  • -Dosgi.console


The most usefull parameter is for me the last one. It allows use of osgi console. 
This command line console active in console log. This console allow :


  • Controlling the OSGi framework
  • Controlling Bundles
  • Displaying Status
  • Extras
  • Controlling Start Level
  • Controlling the Profiling
  • Eclipse Runtime commands
  • Service Component Runtime
  • ...


To get more information, use 
osgi> help
gives :

Exemples  
osgi> ss (Short Status)
gives :

  
osgi> bundle number
provides view on : 


  • Id, 
  • Status,
  • Location,
  • Registered services,
  • Services in use,
  • Exported packages,
  • Imported packages,
  • Host bundles,
  • Class spaces,
  • Required bundles.


Tuesday, April 10, 2012

OSGI Maven bundle for Eclipse (Part 1)

Context
I have a maven project uses many dependencies. I want to use this project as an OSGI bundle. This bundle have to export all its package and dependencies packages, and includes the physical jars.
My first approach was to use apache Felix, maven-copy-dependency and maven-eclipse-plugin.

  • apache felix maven-bundle-plugin for MANIFEST.MF building (including dependencies export)
  • maven-dependency-plugin for jars copy
  • maven-eclipse-plugin for eclipse files update (.classpath and .project)
  • maven-clean-plugin for deleting temporary files.

I finally leave this approch because I could not managed to set up maven plugins producing  the result targeted.

At the end my solution was :

  • apache felix maven-bundle-plugin for MANIFEST.MF building (including dependencies export)
  • maven-dependency-plugin for jars copy
  • specific maven plugin for files update (.classpath)
  • maven-clean-plugin for deleting temporary files.
This solution produces : 
  • a MANISFEST.MF including export package for all maven dependencies
  • a jar including jar dependencies 
  • an eclipse .classpath including all copied dependencies 
Usefull information could be found at  :
My satisfying configuration is giving below (see excerpt).


<project...>
...
  <build>
 <plugins>
   <plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <version>2.3.7</version>
  <extensions>true</extensions>
  <configuration>
    <manifestLocation>META-INF</manifestLocation>
    <instructions>
   <_nouses>true</_nouses>
   <unpackBundle>true</unpackBundle>
   <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
   <Bundle-Version>${project.version}</Bundle-Version>
   <Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment>
   <Import-Package>!*</Import-Package>
   <Export-Package>!target.*,*;-noimport:=true</Export-Package>
   <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
   <Embed-Transitive>true</Embed-Transitive>
   <Embed-Directory>${dependency.outputdirectory}</Embed-Directory>
   <Embed-StripVersion>false</Embed-StripVersion>
   <Bundle-ClassPath>.,{maven-dependencies}</Bundle-ClassPath>
    </instructions>
  </configuration>
  <executions>
    <execution>
   <id>bundle-manifest</id>
   <phase>process-classes</phase>
   <goals>
     <goal>manifest</goal>
   </goals>
    </execution>
  </executions>
   </plugin>
   <plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>2.4.1</version>
  <configuration>
    <filesets>
   <fileset>
     <directory>${basedir}/META-INF</directory>
     <includes>
    <include>**/*.MF</include>
     </includes>
     <followSymlinks>false</followSymlinks>
   </fileset>
   <fileset>
     <directory>${dependency.outputdirectory}</directory>
     <includes>
    <include>**/*.jar</include>
     </includes>
     <followSymlinks>false</followSymlinks>
   </fileset>
    </filesets>
  </configuration>
   </plugin>
   <plugin> 
  <artifactId>maven-dependency-plugin</artifactId> 
  <configuration> 
    <excludeTransitive>false</excludeTransitive> 
  </configuration> 
  <executions> 
    <execution> 
   <id>copy-dependencies</id> 
   <phase>process-classes</phase>
   <goals> 
     <goal>copy-dependencies</goal> 
   </goals> 
   <configuration> 
     <excludeScope>provided</excludeScope> 
     <outputDirectory>${dependency.outputdirectory}</outputDirectory> 
     <overWriteReleases>false</overWriteReleases> 
     <overWriteSnapshots>false</overWriteSnapshots> 
     <overWriteIfNewer>true</overWriteIfNewer> 
   </configuration> 
    </execution> 
  </executions> 
   </plugin> 
   <plugin>
  <groupId>fr.eclipse.plugin</groupId>
  <artifactId>maven-pdeAdapter-plugin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  <configuration />
  <executions>
    <execution>
   <id>managed-classpath-file</id>
   <phase>prepare-package</phase>
   <goals>
     <goal>process-classpath</goal>
   </goals>
    </execution>
  </executions>
   </plugin>
 </plugins>
  </build>
</project>