Creating a Module JAR Using Maven

If you have an existing Liferay module built with Maven that you created from scratch, or you’re upgrading your Maven project from a previous version of Liferay, your project probably can’t generate an executable OSGi JAR. Don’t fret! You can do this by making a few minor configurations in your module’s POMs.

Continue on to see how this is done.

  1. In your project’s pom.xml file, add the BND Maven Plugin declaration:

    <plugin>
        <groupId>biz.aQute.bnd</groupId>
        <artifactId>bnd-maven-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>bnd-process</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    The BND Maven plugin prepares all your Maven module’s resources (e.g., MANIFEST.MF) and inserts them into the generated [Maven Project]/target/classes folder. This plugin prepares your module to be packaged as an OSGi JAR deployable to Liferay DXP.

  2. In your project’s pom.xml file, add the Maven JAR Plugin declaration:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    The Maven JAR plugin builds your Maven project as a JAR file, including the resources generated by the BND Maven plugin. The above configuration also sets the default project MANIFEST.MF file path for your project, which is essential when packaging your module using the BND Maven plugin. By default, the Maven JAR Plugin ignores the target/classes/META-INF/MANIFEST.MF generated by the BND Maven plugin, so you must explicitly set it as the manifest file so it’s included properly in the generated JAR file.

  3. Make sure you’ve added a bnd.bnd file to your Liferay Maven project, residing in the same folder as your project’s pom.xml file.

  4. Build your Maven OSGi JAR by running

    mvn package
    

    Your Maven JAR is generated in your project’s /target folder. You can deploy it manually into Liferay DXP’s /deploy folder, or you can configure your project to deploy automatically to Liferay DXP by following the Deploying a Module Built with Maven to Liferay DXP tutorial.

Fantastic! You’ve configured your Liferay Maven project to package itself into a deployable OSGi module.

« Generating New Projects Using ArchetypesDeploying a Module Built with Maven to Liferay DXP »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0