As part of the distribution, Spring-DM provides a Maven archetype which creates the basic structure of a Java project that uses Spring DM, especially useful to new users. To run the archetype (and create the new project), simply run the following command line:
mvn archetype:generate
The maven plugin will display a selection of possible archetype, from which you should pick
spring-osgi-bundle-archetype (Spring-OSGi archetype)
(currently number 32), and will request input regarding the project about to be created.
A list of all available archetypes included with the plugin and their versions is available here.
Note that it is still possible to select the osgi archetype directly from the command line (i.e. the old way of using the archetype):
mvn archetype:create \ -DarchetypeGroupId=org.springframework.osgi \ -DarchetypeArtifactId=spring-osgi-bundle-archetype \ -DarchetypeVersion= \ -DgroupId=<your-project-groupId> \ -DartifactId=<your-project-artifactId> \ -Dversion=<your-project-version>
Note | |
---|---|
The command above should be invoked as one line - the \ is used as a convenience to break the long line into smaller pieces |
In both cases, the result of the commands is a Maven 2 project that defines two packages (one public and one private) and two Spring configurations:
src/main/resources/META-INF/spring/bundle-context.xml
and src/main/resources/META-INF/spring/bundle-context-osgi.xml
The project is packaged as an OSGi bundle.
Notice that by default, the project does not contain a MANIFEST.MF for your project. The Maven infrastructure will generate it, through Apache Felix bundle plug-in. To do that, run the following (from the project root):
mvn package
Note | |
---|---|
To avoid the confusion between the generated artifacts and maintained files, the manifest file resides under META-INF folder
while Spring configuration files under src/main/resources/META-INF directory. |
This will compile your project, pack it as a jar and create the OSGi manifest based on your classes under /META-INF
folder (so
that users running Eclipse PDE can use it right away. To generate the manifest, without creating the OSGi bundle, simply run:
mvn org.apache.felix:maven-bundle-plugin:manifest
META-INF/MANIFEST.MF
automatically generatedsrc/main/java/<package>
public package exported by the bundlesrc/main/java/<package>/internal
private package, not exported by the bundlesrc/main/resources/META-INF/spring/bundle-context.xml
is a Spring configuration file that defines the simple bean.src/main/resources/META-INF/spring/bundle-context-osgi.xml
is a Spring configuration file ready for you to add bean
definitions from the osgi namespace (services, references etc.).project
, .classpath
, and build.properties
files created to enable use of this
project directly inside eclipse as a PDE plugin project