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:create \ -DarchetypeGroupId=org.springframework.osgi \ -DarchetypeArtifactId=spring-osgi-bundle-archetype \ -DarchetypeVersion=${version} \ -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 |
The result of the command, is a Maven 2 project that defines a simple bean, configures it using
src/main/resources/META-INF/spring/bundle-context.xml
and src/main/resources/META-INF/spring/bundle-context-osgi.xml
and provides unit and (out of the OSGi container) integration tests. 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
for OSGi bundle automatically generatedsrc/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.)BeanImplTest
case defined to unit test the simple beanBeanIntegrationTest
defined to fire up the non-osgi portions of the application context configuration and test
outside of OSGiBeanOgiIntegrationTest
defined to fire up the osgi portions of the application context configuration and test
inside of OSGi.project
, .classpath
, and build.properties
files created to enable use of this
project directly inside eclipse as a PDE plugin project