`

Maven2

阅读更多
•Installing Maven
•Java Installation
•Windows 7
•Linux
•Maven Configuration
•m2eclipse
•Installing m2eclipse
•Import project modules as Maven projects
•Initialize project project
•Build project project



Installing Maven
Java Installation
While Maven can run on Java 1.4, you should run at least Java 5. Go with the most recent stable Java Development Kit (JDK) available for your operating system.

?
$ java -versionjava version "1.6.0_20"OpenJDK Runtime Environment (IcedTea6 1.9.10) (6b20-1.9.10-0ubuntu1~10.04.2)OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
Windows 7
•Download apache-maven-2.2.1-bin.zip from http://maven.apache.org/download.html.
•Unzip in C:\Program Files\Apache Software Foundation.
•Add environment variable M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1. (to see how to add, modify, remove environment variables on windows 7 : [])
•Add environment variable M2 =%M2_HOME%\bin.
•Upgrade the environment variable Path by adding $M2 and $JAVA_HOME.
Linux
•Download apache-maven-2.2.1-bin.tar.gz from http://maven.apache.org/download.html.
•Pick an appropriate place for it to live, and expand the archive there. If you expanded the archive into the directory /usr/local/apache-maven-2.2.1, you may want to create a symbolic link to make it easier to work with and to avoid the need to change any environment
configuration when you upgrade to a newer version:
?
/usr/local % cd /usr/local/usr/local % ln -s apache-maven-2.2.1 maven/usr/local % export M2_HOME=/usr/local/maven/usr/local % export PATH=${M2_HOME}/bin:${PATH}
•You’ll need to add both M2_HOME and PATH to a script that will run every time you login. To do this, add the following lines to .bash_login.
?
export M2_HOME=/usr/local/mavenexport PATH=${M2_HOME}/bin:${PATH}
Once you’ve added these lines to your own environment, you will be able to run Maven from the command line.

Maven Configuration
In $M2_HOME/conf/settings.xml :

Copy the file settings.xml if it is not present in the directory :
C:\Documents and Settings\username\.m2\

You need login password on nexus server. To obtain them, send an email to *project support mailing list

You can set up the nexus access parameters and the access parameters to your local tomcat (how to configure your tomcat) :

?
<servers>      <server>          <id>project _projects_releases</id>          <username>YOUR_NEXUS_LOGIN</username>          <password>YOUR_NEXUS_PWD</password>      </server>      <server>          <id>project _projects_snapshots</id>          <username>YOUR_NEXUS_LOGIN</username>          <password>YOUR_NEXUS_PWD</password>      </server>      <server>           <id>tomcat</id>           <username>YOUR_LOCAL_TOMCAT_LOGIN</username>           <password>YOUR_LOCAL_TOMCAT_PWD</password>      </server>      <server>           <id>tomcat_project </id>           <username>admin</username>           <password>admin</password>      </server>  </servers>


m2eclipse
The goal of the Eclipse m2eclipse project is to provide Apache Maven support in the Eclipse IDE, making it easier to edit Maven's pom.xml, run a build from the IDE and much more.

Installing m2eclipse
In your eclipse environment (Indigo 3.7) :

•Help -> Install new software...
•Write the URL http://m2eclipse.sonatype.org/sites/m2e in field Work with
•Select m2e - Maven Integration for Eclipse
•Accept the license terms and finish
•Restart eclipse
To display POM files as xml files :

•Window -> Preferences
•Maven -> User interface
•Select the two options as shown in the following screenshot, then click OK



Import project modules as Maven projects
In this section, we suppose that you have already import project project with the Egit plugin (2_Git with Eclipse).

In your Package explorer, you can now see the project project.

To import all the Maven modules, select the project project in the Package explorer and right click in a free area in this window.

Select import -> Existing Maven Project -> select all the module except the project module and finish.

Initialize project project
Before continuing, follow the instructions here:

4_Installing and configuring Tomcat

5_Mysql server configuration

On eclipse launch a maven build on project project  :

•Right click on the project/module you want to build
•Select Run As -> Maven Build...
•The following window appears :


Goals : clean install

Profiles : development integration

Select Skip Tests option.

Build project project


•Right click on the project/module you want to build
•Select Run As -> Maven Build...
•The following window appears :




In the field Goals, define the two following actions for project project :

?
Goals : clean install
•This command :
•builds the targets
•runs the unitary tests  (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin
_______________________________________________________________________________________________________________________________________________________________________________________________________

?
Goals : clean installProfiles : integration
•This command activates the integrationprofile defined in pom.xml files :
•builds the targets
•runs the unitary tests (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin
•deploys the war files on local Tomcat
•resets the mysql databases on localhost
•performs the integration tests (tests prefixed by TI)
_______________________________________________________________________________________________________________________________________________________________________________________________________

Important : development profile has to be always added in Profiles field when you are developping :

?
Goals : clean installProfiles : development
•This command activates the developmentprofile defined in pom.xml files :
•replaces the configuration files (log4j.poperties, web.xml...) with the appropriate configuration files  for development (log4j_developement.poperties, web-development.xml...)
•builds the targets
•runs the unitary tests (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin
_______________________________________________________________________________________________________________________________________________________________________________________________________----

Important : you can activate two (or more) profiles in a build, e.g. :

?
Goals : clean installProfiles : development integration
•This command activates the development and the integrationprofiles defined in pom.xml files :
•replaces the configuration files (log4j.poperties, web.xml...) with the appropriate configuration files  for development (log4j_developement.poperties, web-development.xml...)
•builds the targets
•runs the unitary tests (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin
•deploys the war files on local Tomcat
•resets the mysql databases on localhost
•performs the integration tests (tests prefixed by TI)
_______________________________________________________________________________________________________________________________________________________________________________________________________----

?
Goals : clean installProfiles : development integration soapui
•This command activates the development and the integrationprofiles defined in pom.xml files :
•replaces the configuration files (log4j.poperties, web.xml...) with the appropriate configuration files  for development (log4j_developement.poperties, web-development.xml...)
•builds the targets
•runs the unitary tests (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin
•deploys the war files on local Tomcat
•resets the mysql databases on localhost
•performs the integration tests (tests prefixed by TI)
•performs the soapui tests
_______________________________________________________________________________________________________________________________________________________________________________________________________     

       Be careful : use the next profile only for PRODUCTION build !

?
Goals : clean installProfiles : production
•This command activates the productionprofile defined in pom.xml files :
•replaces the configuration files (log4j.poperties, web.xml...) with the appropriate configuration files for production (log4j_developement.poperties, web-development.xml...)
•builds the targets
•runs the unitary tests (tests prefixed by TU)
•runs the code coverage with the cobertura maven plugin


Build lifecycle

Lifecycles phases are described in the following table. Bold phases are the most used.

Lifecycle Phase
Description

validate
Validate the project is correct and all necessary
information is available to complete a build

generate-sources
Generate any source code for inclusion in
compilation

process-sources
Process the source code, for example to filter any
values

generate-resources
Generate resources for inclusion in the package

process-resources
Copy and process the resources into the destination
directory, ready for packaging

compile
Compile the source code of the project

process-classes
Post-process the generated files from compilation,
for example to do bytecode enhancement on Java
classes

generate-test-sources
Generate any test source code for inclusion in
compilation

process-test-sources
Process the test source code, for example to filter
any values

generate-test-resources
Create resources for testing

process-test-resources
Copy and process the resources into the test
destination directory

test-compile
Compile the test source code into the test
destination directory

test
Run tests using a suitable unit testing framework. These
tests should not require the code be packaged or deployed

prepare-package
Perform any operations necessary to prepare a
package before the actual packaging. This often
results in an unpacked, processed version of the
package (coming in Maven 2.1+)

package
Take the compiled code and package it in its
distributable format, such as a JAR, WAR, or EAR

pre-integration-test
Perform actions required before integration tests are
executed. This may involve things such as setting
up the required environment

integration-test
Process and deploy the package if necessary into an
environment where integration tests can be run

post-integration-test
Perform actions required after integration tests have
been executed. This may include cleaning up the
environment

verify
Run any checks to verify the package is valid and
meets quality criteria

install
Install the package into the local repository, for use
as a dependency in other projects locally

deploy
Copies the final package to the remote repository
for sharing with other developers and projects
(usually only relevant during a formal release)

Some useful Maven command lines
At the top of your Maven project :

•Clean

?mvn clean
•See the dependencies tree

?mvn dependency:tree
•Compile

?mvn compile
•Compile and Test

?mvn test
•Compile, Test and generate target


?
mvn install


•Install and skip tests

?mvn install -Dmaven.test.skip=true
•Install and see if the dependencies are up to date


?
mvn install org.codehaus.mojo:versions-maven-plugin:1.2:display-dependency-updates


•Help


?
mvn help




M2eclipse
The goal of the Eclipse m2eclipse project is to provide Apache Maven support in the Eclipse IDE, making it easier to edit Maven's pom.xml, run a build from the IDE and much more.

Features
•Creating and importing Maven projects
•Dependency management and integration with the Eclipse classpath
•Automatic dependency downloads and updates
•Artifact Javadoc and source resolution
•Creating projects with Maven Archetypes
•Browsing and searching remote Maven repositories
•POM management with automatic update to dependency list
•Materializing a project from a Maven POM
•Checking out a Maven project from several SCM repositories
•Adapting nested multi-module Maven projects to the Eclipse IDE
•Integration with Web Tools Project ( WTP)
•Integration with AspectJ Development Tools ( AJDT)
•Integration with Subclipse, a Subversion Plugin for Eclipse
•Integration with Mylyn, a plugin that provides task-oriented context and integration with tools like JIRA and other issue/task-management systems.
Usage
M2eclipse usage is described in http://www.theserverside.com/news/1363817/Introduction-to-m2eclipse.

Build
•Right click on the project/module you want to build
•Select Run As -> Maven Build...
•The following window appears :


•In field goals, you define the action to perform, for example :
•clean : clean the project/module
•compile : compile
•test : compile and test
•install : compile, test and generate target
•deploy : compile, test, generate target and deploy the .jar .war on the nexus
•Ones you have created a build configuration, it is saved and you can reuse it by selecting Run Configurations
  • 大小: 55.4 KB
  • 大小: 81 KB
  • 大小: 77 KB
分享到:
评论

相关推荐

    maven2 的eclipse插件

    maven2的eclipse插件 for eclipse 3.5+。 插件安装时,我们只需在eclipse根目录下新建一个【links】目录,然后在里面创建【.link】扩展名的文件,在里面写上类似于【path=F:\\IDE\\eclipsePlugin\\maven2】这样的...

    maven2的包

    maven2的包maven的容器可以作为客户端

    Maven 2 Eclipse Plugin

    Maven 2 Eclipse Plugin

    maven2完全使用手册

    maven2完全使用手册 全面介绍maven2 使用及配置 docx格式

    maven2之m2eclipse使用手册

    maven2之m2eclipse使用手册.doc

    maven2详细教程

    maven2详细教程

    maven2maven3eclipse通用版本插件

    支持maven2 maven3 通用版本eclipse插件,在maven官网下载apache-maven-3.2.1-bin.zip,解压插件压缩包到path=D:\m2e-0.12.0.20101115-1102 在eclipse新建links文件夹,新建文件maven23.link,内容为:path=D:/m2e-...

    maven2详细教程.doc

    maven2详细教程.doc

    Maven2完全使用手册

    Maven2使用全攻略,包含了maven常用的各个标签讲解,十分有用!

    Maven2使用项目开发规范说明.doc

    《Maven2使用项目开发规范说明》,图文并茂,详细介绍了使用 Maven2 开发一个规范项目的流程。 目录: 1. 环境配置 3 1.1. 配置Maven2 3 1.2. 配置Eclipse环境变量MIA_LIB 4 1.3. 安装Maven2 的eclipse plugin 4 2. ...

    Artifactory设置Maven2组件库

    使用Artifactory设置Maven2组件库

    Maven2 配置指南(java 项目管理之路)

    java,maven2,项目管理,Maven2 配置指南(java 项目管理之路)

    Maven2构建.doc

    Maven2构建.doc Maven2构建.doc Maven2构建.doc

    maven2 jar包

    maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包 maven2 jar包

    maven2快速入门教程

    maven教程,里面有三个,全为txt格式,用于快速了解、使用maven

    maven2 (maven2的免安装程序,非插件)

    此资源是maven2的免安装程序,并非插件,可以在环境变量中配置路径,对于初次接触maven2的开发人员,建议不要使用Eclipse自带的插件,尝试自己配置会掌握更多的东西

    Maven2资源和配置下载

    搭建MyEclipse私服、包裹maven文件

    Maven2_资料分享

    包含:Maven2_基础教程.pdf\《Maven权威指南》-电子书下载(PDF)(中文)\maven2完全使用手册.docx\Maven3实战笔记04Maven的生命周期和插件.doc\Maven实战.pdf\Maven学习指南.pdf

    Eclipse的Maven2插件.zip

    官网公布的 Eclipse 的 Maven2 插件,本插件版本是:m2e-0.12.0.20101115-1102,大小 11 MB。 关于安装 Maven2 插件到 Eclipse 的详细步骤,请参考博客《集成 Maven 2 插件到 eclipse 的过程》,博客地址:...

    maven2离线安装包

    eclipse IDE 如果是3.5或以上,直接解压到eclipse\dropins目录下。 低于3.5可选择link方式试下。

Global site tag (gtag.js) - Google Analytics