This post is a quick start guide to using the Maven PAX plugin to create OSGi project and start an OSGi runtime environment (Apache Felix). First, use the Maven Pax Plugin from OPS4J, and call the create-project goal. The following command-line will create a multi-module project with a groupId of org.sonatype.mhandbook, an artifactId of osgi-project, and a version of 1.0-SNAPSHOT:
~/examples/osgi $ mvn org.ops4j:maven-pax-plugin:create-project \ -DgroupId=org.sonatype.mhandbook \ -DartifactId=osgi-project \ -Dversion=1.0-SNAPSHOT [INFO] Scanning for projects... [INFO] artifact org.ops4j:maven-pax-plugin: checking for updates from central [INFO] Building Maven Default Project [INFO] task-segment: [org.ops4j:maven-pax-plugin:create-project] (aggregator -style) [INFO] [pax:create-project] [INFO] Selecting latest archetype release within version range [1,2) [INFO] artifact org.ops4j.pax.construct:maven-archetype-osgi-project: checking for updates from central [INFO] Using following parameters for creating Archetype: maven-archetype-osgi- project:1.0.3 [INFO] Parameter: packageName, Value: org.sonatype.mhandbook.osgi-project [INFO] Parameter: archetypeVersion, Value: 1.0.3 [INFO] Parameter: groupId, Value: org.sonatype.mhandbook [INFO] Parameter: archetypeArtifactId, Value: maven-archetype-osgi-project [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: archetypeGroupId, Value: org.ops4j.pax.construct [INFO] Parameter: basedir, Value: ~/examples/osgi [INFO] Parameter: package, Value: org.sonatype.mhandbook.osgi-project [INFO] Parameter: artifactId, Value: osgi-project [INFO] ********************* End of debug info from resources from generated POM [INFO] Archetype created in dir: ~/examples/osgi/osgi-project
Once you’ve generated an OSGi project using the Pax Plugin, you will have the following directory structure:

