Default

How to use this template:

    • Create a new pom.xml in an empty Java project (you can create the Java project using eclipse, just make sure to specify src/main/java as source directory and target/classes as output directory).
    • Create a default public and private super-package for your project (eg. "com.example.mypackage" and "com.example.mypackage.internal")
    • Copy the template below into the pom.xml file and fill out the placeholders ([XXX]) with sensible values.
    • Test whether you can create an eclipse project without problems by executing mvn eclipse:clean clean package eclipse:eclipse -Declipse.pde -Declipse.useProjectReferences=false install

Features of this template:

    • Allows to create eclipse project using mvn eclipse:eclipse.
    • Allows dependencies to other projects in the eclipse workspace
    • Automatically generates OSGi meta-data for the module (so it can be used with eclipse PDE)

Constraints of this template:

    • Does not allow dependencies to any external libraries, which are not represented as project in the same eclipse workspace as the project.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Template: https://sites.google.com/site/eclipsemaven/default -->
<project>
    <groupId>[XXX]</groupId>
    <artifactId>[XXX]</artifactId>
    <version>[XXX]</version>
    <properties>
        <module.importedPackages>
            *
        </module.importedPackages>
        <module.exportedPackages>![XXX].internal*,[XXX]*
        </module.exportedPackages>
        <module.serviceDefinitions>
        </module.serviceDefinitions>
    </properties>
    <!-- Dependent Modules -->
    <dependencies>
        <dependency>
            <groupId>[XXX]</groupId>
            <artifactId>[XXX]</artifactId>
            <version>[0.0.1,)</version>
        </dependency>
    
    </dependencies>
    <!-- XXXXXXXXXXXXXX Maven declarations XXXXXXXXXXXXXXXXXX -->
    <modelVersion>4.0.0</modelVersion>
    <name>${project.artifactId}</name>
    <packaging>bundle</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <!-- FOR BUNDLE MANAGEMENT -->
            <!-- The Maven bundle plugin generates Meta-data required for OSGi -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <version>2.2.0</version>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Import-Package>${module.importedPackages}</Import-Package>
                        <Export-Package>${module.exportedPackages}</Export-Package>
                        <Service-Component>${module.serviceDefinitions}
                        </Service-Component>
                        <Bundle-RequiredExecutionEnvironment>JavaSE-1.6
                        </Bundle-RequiredExecutionEnvironment>
                    </instructions>
                </configuration>
            </plugin>
            <!-- FOR MAVEN ECLIPSE PLUGIN -->
            <!-- Dependency Plugin used to copy the dependency JARs into the root
                project folder. There the Maven eclipse plugin will add them to the classpath
                of PDE projects. -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Cleanup necessary because of PDE tweaks, clear the project directory -->
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}</directory>
                            <includes>
                                <include>*.jar</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <!-- Keep the MANIFEST.MF used by eclipse in sync with the MANIFEST.MF
                created by the maven bundle plugin -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <delete file="${basedir}/META-INF/MANIFEST.MF" />
                                <copy file="src/main/webapp/WEB-INF/classes/META-INF/MANIFEST.MF"
                                    tofile="${basedir}/META-INF/MANIFEST.MF" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!-- RESOURCES -->
        <resources>
           
            <!-- This entry makes sure that resources, which lie in the same package
                as Java classes, are copied into the target. Often external libraries require
                resources, which are loaded using Class.getResource or Class.getResourceAsStream
                and which are in a subpackage of the class. For instance, the NetBeans template
                for the Swing Application Framework does so. -->
            <resource>
                <filtering>false</filtering>
                <directory>src/main/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
            <!-- This entry makes sure component definitions for OSGi declarative
                services are copied into the destination -->
            <resource>
                <targetPath>OSGI-INF</targetPath>
                <filtering>false</filtering>
                <directory>OSGI-INF</directory>
                <includes>
                    <include>**</include>
                </includes>
            </resource>
            <!-- I really do not know why know a manual entry for src/main/resources
                is necessary? It should be included following the Maven convention. -->
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>