转:maven Package-specific Lifecycles

The specific goals bound to each phase default to a set of goals specific to a project’s packaging. A project with packaging jar has a different set of default goals from a project with a packaging of war. The packaging element affects the steps required to build a project. For an example of how the packaging affects the build, consider two projects: one with pom packaging and the other with jar packaging. The project with pom packaging will run the site:attach-descriptor goal during the package phase, and the project with jar packaging will run the jar:jar goal instead.

The following sections describe the lifecycle for all built-in packaging types in Maven. Use these sections to find out what default goals are mapped to default lifecycle phases.

4.2.1. JAR

JAR is the default packaging type, the most common, and thus the most commonly encountered lifecycle configuration. The default goals for the JAR lifecycle are shown in Table 4.2, “Default Goals for JAR Packaging”.

Table 4.2. Default Goals for JAR Packaging

Lifecycle Phase

Goal

process-resources

resources:resources

compile

compiler:compile

process-test-resources

resources:testResources

test-compile

compiler:testCompile

test

surefire:test

package

jar:jar

install

install:install

deploy

deploy:deploy


4.2.2. POM

POM is the simplest packaging type. The artifact that it generates is itself only, rather than a JAR, SAR, or EAR. There is no code to test or compile, and there are no resources the process. The default goals for projects with POM packaging are shown in Table 4.3, “Default Goals for POM Packaging”.

Table 4.3. Default Goals for POM Packaging

Lifecycle Phase

Goal

package

site:attach-descriptor

install

install:install

deploy

deploy:deploy


4.2.3. Maven Plugin

This packaging type is similar to JAR packaging type with three additions: plugin:descriptor,plugin:addPluginArtifactMetadata, and plugin:updateRegistry. These goals generate a descriptor file and perform some modifications to the repository data. The default goals for projects with plugin packaging are shown inTable 4.4, “Default Goals for Plugin Packaging”.

Table 4.4. Default Goals for Plugin Packaging

Lifecycle Phase

Goal

generate-resources

plugin:descriptor

process-resources

resources:resources

compile

compiler:compile

process-test-resources

resources:testResources

test-compile

compiler:testCompile

test

surefire:test

package

jar:jar, plugin:addPluginArtifactMetadata

install

install:install, plugin:updateRegistry

deploy

deploy:deploy


4.2.4. EJB

EJBs, or Enterprise Java Beans, are a common data access mechanism for model-driven development in Enterprise Java. Maven provides support for EJB 2 and 3. Though you must configure the EJB plugin to specifically package for EJB3, else the plugin defaults to 2.1 and looks for the presence of certain EJB configuration files. The default goals for projects with EJB packaging are shown in Table 4.5, “Default Goals for EJB Packaging”.

Table 4.5. Default Goals for EJB Packaging

Lifecycle Phase

Goal

process-resources

resources:resources

compile

compiler:compile

process-test-resources

resources:testResources

test-compile

compiler:testCompile

test

surefire:test

package

ejb:ejb

install

install:install

deploy

deploy:deploy


4.2.5. WAR

The WAR packaging type is similar to the JAR and EJB types. The exception being the package goal of war:war. Note that the war:war goal requires a web.xml configuration in your src/main/webapp/WEB-INF directory. The default goals for projects with WAR packaging are shown in Table 4.6, “Default Goals for WAR Packaging”.

Table 4.6. Default Goals for WAR Packaging

Lifecycle Phase

Goal

process-resources

resources:resources

compile

compiler:compile

process-test-resources

resources:testResources

test-compile

compiler:testCompile

test

surefire:test

package

war:war

install

install:install

deploy

deploy:deploy


4.2.6. EAR

EARs are probably the simplest Java EE constructs, consisting primarily of the deployment descriptor application.xmlfile, some resources and some modules. The EAR plugin has a goal named generate-application-xml which generates the application.xml based upon the configuration in the EAR project’s POM. The default goals for projects with EAR packaging are shown in Table 4.7, “Default Goals for EAR Packaging”.

Table 4.7. Default Goals for EAR Packaging

Lifecycle Phase

Goal

generate-resources

ear:generate-application-xml

process-resources

resources:resources

package

ear:ear

install

install:install

deploy

deploy:deploy


4.2.7. Other Packaging Types

This is not an exhaustive list of every packaging type available for Maven. There are a number of packaging formats available through external projects and plugins: the NAR (native archive) packaging type, the SWF and SWC packaging types for projects that produce Adobe Flash and Flex content, and many others. You can also define a custom packaging type and customize the default lifecycle goals to suit your own project packaging requirements.

To use one of these custom packaging types, you need two things: a plugin which defines the lifecycle for a custom packaging type and a repository which contains this plugin. Some custom packaging types are defined in plugins available from the central Maven repository. Here is an example of a project which references the Israfil Flex plugin and uses a custom packaging type of SWF to produce output from Adobe Flex source.

Custom Packaging Type for Adobe Flex (SWF). 

<project>
    ...
    <packaging>swf</packaging>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>net.israfil.mojo</groupId>
                <artifactId>maven-flex2-plugin</artifactId>
                <version>1.4-SNAPSHOT</version>
                <extensions>true</extensions>
                <configuration>
                    <debug>true</debug>
                    <flexHome>${flex.home}</flexHome>
                    <useNetwork>true</useNetwork>
                    <main>org/sonatype/mavenbook/Main.mxml</main>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

 

In Section 11.6, “Plugins and the Maven Lifecycle”, we show you how to create your own packaging type with a customized lifecycle. This example should give you an idea of what you’ll need to do to reference a custom packaging type. All you need to do is reference the plugin which supplies the custom packaging type. The Israfil Flex plugin is a third-party Maven plugin hosted at Google Code, for more information about this plugin and how to use Maven to compile Adobe Flex go to http://code.google.com/p/israfil-mojo. This plugin supplies the following lifecycle for the SWF packaging type:

Table 4.8. Default Lifecycle for SWF Packaging

Lifecycle Phase

Goal

compile

flex2:compile-swc

install

install:install

deploy

deploy:deploy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值