Chapter 3. Building with Maven
3.1. Maven Directory Structure
src/main/javaand put the results into
Standard directory layout
Example 3.1. Standard Maven Directory Layout
ProjectDir/ pom.xml src/ main/ java/ ... resources/ META-INF/ spring/ *.xml OSGI-INF/ blueprint/ *.xml test/ java/ resources/ target/ ...
pom.xmlfile is the Project Object Model (POM) for the current project, which contains a complete description of how to build the current project. A
pom.xmlfile can be completely self-contained, but frequently (particular for more complex Maven projects) it can import settings from a parent POM file.
pom.xmlfile is automatically embedded at the following location in the generated JAR file:
src and target directories
src/directory contains all of the code and resource files that you will work on while developing the project.
target/directory contains the result of the build (typically a JAR file), as well as all all of the intermediate files generated during the build. For example, after performing a build, the
target/classes/directory will contain a copy of the resource files and the compiled Java classes.
main and test directories
src/main/directory contains all of the code and resources needed for building the artifact.
src/test/directory contains all of the code and resources for running unit tests against the compiled artifact.
java/sub-directory contains Java source code (
*.javafiles) with the standard Java directory layout (that is, where the directory pathnames mirror the Java package names, with
/in place of the
src/main/java/directory contains the bundle source code and the
src/test/java/directory contains the unit test source code.
src/main/resources/directory. The files and directories under
src/main/resources/will be copied into the root of the JAR file that is generated by the Maven build process.
src/test/resources/are used only during the testing phase and will not be copied into the generated JAR file.
META-INF/spring/*.xml, in your bundle. One of the key consequences of having Spring DM enabled in the OSGi container is that the lifecycle of the Spring application context is automatically synchronized with the OSGi bundle lifecycle:
- Activation—when a bundle is activated, Spring DM automatically scans the bundle to look for Spring configuration files in the standard location (any
.xmlfiles found under the
META-INF/spring/directory). If any Spring files are found, Spring DM creates an application context for the bundle and creates the beans defined in the Spring configuration files.
- Stopping—when a bundle is stopped, Spring DM automatically shuts down the bundle's Spring application context, causing any Spring beans to be deleted.
OSGI-INF/blueprint/*.xml, in your project. For more details about the blueprint container, see Chapter 16, OSGi Services.