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:
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>
|The command above should be invoked as one line - the |
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:
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):
|To avoid the confusion between the generated artifacts and maintained files, the manifest file resides under |
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:
src/main/java/<package>public package exported by the bundle
src/main/java/<package>/internalprivate package, not exported by the bundle
src/main/resources/META-INF/spring/bundle-context.xmlis a Spring configuration file that defines the simple bean.
src/main/resources/META-INF/spring/bundle-context-osgi.xmlis a Spring configuration file ready for you to add bean definitions from the osgi namespace (services, references etc.)
build.propertiesfiles created to enable use of this project directly inside eclipse as a PDE plugin project