資料 リソース
Liferayは、コミュニティにてテクノロジーをより良く使うために役立つ豊富なリソースと知識を提供しています。
Creating Liferay Plugins with Maven
Liferay offers many archetypes to help create Maven projects for multiple plugin types, including portlet, theme, hook, and layout template plugins. We provide archetypes for each of these plugin types for various versions of Liferay, so you almost certainly have the archetype you need.
Archetype is Maven’s project templating toolkit. Let’s use it to create a Liferay portlet project. With Archetype, you can use the same steps we detail below to generate Liferay plugin projects of any type.
Note: Make sure Maven is installed and that it’s executable is in your path environment variable.
Here’s how you use Maven archetypes to generate a Liferay plugin project:
Open the command prompt and navigate to the parent directory in which you want to create the plugin project. Archetype will create a sub-directory for the plugin project you create.
Note: If you haven’t already created a parent project, you may want to consider creating one to share common project information. See section Using a Parent Plugin Project for details.
Execute the command
mvn archetype:generateArchetype starts and lists the archetypes available to you. You’ll be prompted to choose an archetype or filter archetypes by group / artifact ID. The output looks similar to the following text:
... 39: remote -> com.liferay.maven.archetypes:liferay-hook-archetype (Provides an archetype to create Liferay hooks.) 40: remote -> com.liferay.maven.archetypes:liferay-layouttpl-archetype (Provides an archetype to create Liferay layout templates.) 41: remote -> com.liferay.maven.archetypes:liferay-portlet-archetype (Provides an archetype to create Liferay portlets.) 42: remote -> com.liferay.maven.archetypes:liferay-portlet-icefaces-archetype (Provides an archetype to create Liferay ICEfaces portlets.) 43: remote -> com.liferay.maven.archetypes:liferay-portlet-jsf-archetype (Provides an archetype to create Liferay JSF portlets.) ... Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):To find the right Liferay archetype for your project, you can either scroll up to find it or apply filters to narrow the set of results. Filtering on liferay as your group ID, and a plugin type (portlet, hook, theme, etc.) can help you focus on more applicable Liferay archetypes.
Entering
liferay:portletas a filter gives a listing of Liferay portlet archetypes:Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : liferay:portlet Choose archetype: 1: remote -> com.liferay.maven.archetypes:liferay-portlet-archetype (Provides an archetype to create Liferay portlets.) 2: remote -> com.liferay.maven.archetypes:liferay-portlet-icefaces-archetype (Pr ovides an archetype to create Liferay ICEfaces portlets.) 3: remote -> com.liferay.maven.archetypes:liferay-portlet-jsf-archetype (Provide s an archetype to create Liferay JSF portlets.) 4: remote -> com.liferay.maven.archetypes:liferay-portlet-liferay-faces-alloy-ar chetype (Provides an archetype to create Liferay Faces Alloy portlets.) 5: remote -> com.liferay.maven.archetypes:liferay-portlet-primefaces-archetype ( Provides an archetype to create Liferay PrimeFaces portlets.) 6: remote -> com.liferay.maven.archetypes:liferay-portlet-richfaces-archetype (P rovides an archetype to create Liferay RichFaces portlets.) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co ntains): :Choose an archetype by entering its number.
You’re next prompted to choose the archetype version. Enter the number corresponding to the Liferay version for the archetype. However, you’re not required to select the archetype version that corresponds with your Liferay instance; older archetype versions are compatible with updated Liferay bundles.
The snapshot below illustrates choosing the archetype version:
Figure 8.6: You’re prompted by Maven Archetype to enter the archetype version.
Enter values for the groupId, artifactId, version, and package coordinates (properties) of your project. Here are some examples:
groupId: com.liferay.sample artifactId: sample-portlet version: 1.0-SNAPSHOT package: com.liferay.sampleThis process is illustrated in the snapshot below:
Figure 8.7: When creating your portlet plugin, you must enter your groupId, artifactId, version, and package properties.
For more information on defining Maven coordinates, see http://maven.apache.org/pom.html#Maven_Coordinates.
Enter the letter
Yto confirm your coordinates.Maven’s Archetype tool creates a Liferay plugin project directory with a new
pom.xmlfile and source code.
Note: The archetype file is downloaded and installed automatically to your local repository (e.g., .m2/repository/com/liferay/maven/archetypes/<archetype>). If you configured the mirror pointing to your public repository on Nexus, the plugin is installed there.
Figure 8.8: Your archetype and its dependencies are now available in your local repository.
Following these steps, you can use Archetype to generate all your Liferay plugins!
Plugin projects generated from a Liferay archetype are equipped with a POM that’s ready to work with a parent project. It inherits the values for liferay.version and liferay.auto.deploy.dir properties from the parent.
When your plugin is created, you can package and deploy your project to a specified Liferay instance. You can even install and deploy the individual plugin to a remote repository.
Next we’ll go through some brief examples to demonstrate deploying your plugins to Liferay Portal using Maven.