`

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离线安装包

    标题“maven2离线安装包”指的是针对Maven 2的不依赖网络环境的安装包,主要用于在没有互联网连接或者网络环境不稳定的情况下安装和使用Maven。Maven是一个项目管理和综合工具,它简化了Java项目的构建、依赖管理和...

    Maven 2 Eclipse Plugin

    Maven 2 Eclipse Plugin 是一个强大的开发工具,它将Apache Maven的构建功能与Eclipse IDE紧密集成,使得Java开发者能够在Eclipse环境中无缝地管理项目依赖、构建和测试。这个插件极大地简化了Maven项目的配置和管理...

    maven2 的eclipse插件

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

    Maven2资源和配置下载

    本篇文章将深入探讨"Maven2资源和配置下载"的主题,以及如何在MyEclipse环境中搭建私有仓库(私服)来管理和分发Maven文件。 首先,Maven2是Apache软件基金会开发的一款构建工具,它通过XML格式的POM(Project ...

    Apache Maven 2 Effective Implementation

    ### Apache Maven 2 有效实施知识点详解 #### 一、Apache Maven 2 概述 Apache Maven 是一个项目管理和理解工具。它包含了构建过程(build process)、软件项目信息和最佳实践指南。Maven 的主要目标是让构建过程...

    maven2之m2eclipse使用手册

    maven2之m2eclipse使用手册.doc

    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 (maven2的免安装程序,非插件)

    Maven2 是一个强大的项目管理和构建工具,它主要应用于Java开发领域,尤其在Web开发中扮演着重要角色。Maven通过自动化构建过程,包括编译、测试、打包、部署等步骤,大大简化了项目的管理工作。与Eclipse中的Maven...

    maven2 eclipse

    标题 "maven2 eclipse" 暗示了我们要讨论的是如何在 Eclipse 集成管理 Maven 项目。这篇博文可能是关于如何将 Maven 2.x 集成到 Eclipse 开发环境中,以便更有效地构建和管理Java项目。Maven 是一个项目管理和综合...

    maven2-xdoclet2-plugin-2.0.5.jar

    maven2-xdoclet2-plugin-2.0.5.jar

    maven2的学习记录.docx

    Maven2 基础知识点总结 Maven2 是一个基于 Java 的项目管理和构建工具,提供了一个灵活的方式来管理项目的构建、报告和文档。下面是 Maven2 的一些基础知识点总结。 一、Maven2 项目结构 Maven2 项目结构主要分为...

    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教程和源码

    ** Maven2 概述 ** Maven 是一个项目管理和综合工具,主要应用于Java开发环境。Maven2 是 Maven 的一个版本,它简化了构建过程,通过自动化构建生命周期和依赖管理来帮助开发者。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 的过程》,博客地址:...

    Better builds with Maven2源代码

    《构建优化:深入理解Maven2源代码》 在软件开发过程中,构建工具扮演着至关重要的角色,它们负责管理依赖、编译代码、打包应用以及执行测试等任务。Maven2,作为Java领域广泛使用的自动化构建工具,因其强大的功能...

    Maven 2 使用手册

    Maven 2 使用手册,chm中文格式。

    Maven2Eclipse

    Maven2Eclipse.解压后,直接把Maven文件夹整个复制到:eclipse-jee-helios-SR1-win32\eclipse\dropins下就行了。如果没有这个文件夹,你的Eclipse版本太低了,用老方法,link那种方式去折腾吧。

    maven2-xdoclet2-plugin-2.0.6.jar

    maven2-xdoclet2-plugin-2.0.6.jar

    Maven2教程入门基础

    Maven2教程,项目构建使用,一起学习

Global site tag (gtag.js) - Google Analytics