http://www.cnblogs.com/flyingzqx/archive/2009/12/03/1616201.html maven2 start I believe everyone maven1 already very familiar with the specific maven can do, is not explained in detail. Personally feel that the open-source projects using maven or relatively more within the company, it is not clear. I've used the company for some time, but that was not below the. With the maven1 compared, maven2 can be regarded as virtually rewritten, but from the speed it should be faster. Several major new features include: (detailed reference http://www.ibm.com/developerworks/cn/opensource/os-maven2/index.html) 1. Faster and easier than the ant can be in terms of speed of 2. Fewer configuration file configuration file is now only in the settings.xml and pom.xml. 3. Plugin language change language began to support java, BeanShell, and ant 4. Provides a pre-defined template, which is most helpful, users can define their own project their own template, just as the same as with the appfuse project structure is generated 5. The introduction of life-cycle in the Maven2 have a clear concept of life cycle, but also offer corresponding command, making the project to build a more clarity. 6. New Dependency Scope This is also more important, some are used for test range of packages, you can not join the dependence of the 7. Transitive dependencies, simplifying dependency management it is most convenient, and can save a lot of configuration. As a dependent on b, b will be dependent on a dependent on c default c. But will also have hidden dangers, such as the version of the conflict. But maven has also been taken into account, and can be used exclusions to exclude duplication of the corresponding dependence.

Introduced so many, and now cut into the issues that are beginning maven2 Tour: The first need to download these tools: maven2: http://maven.apache.org/download.html the most important maven-proxy: to proxy repository, use the local library instead of the remote repository maven2 http://maven-proxy.codehaus.org/ continuum: a nice continuous integration tool for automated build. Support for ant, maven http://maven.apache.org/continuum/ svn: version control tools that have been configured. maven for eclipse plug-ins, the main station in the maven has downloaded, it is true plug-ins. Of course, there are a corresponding plug-in idea Finally, http, the server is essential. Developed for internal use. You can use apache, or the jetty http://www.mortbay.org/

maven2 installation: Install maven2 is very simple to download to the maven package solved on the list. (Currently I have the configuration in win2003, but also does not apply to linux, all of the configuration for all the windows). To increase the corresponding environment variable m2_home = maven2 installation directory, do not forget to set java_home directory. Also in path to increase% m2_home% \ bin; can be used directly in the command line the following mvn. Other tools installed in the follow-up article will introduce.

Start the first one mvean2 projects: mvn archetype: create-DgroupId = com.mycompany.app \-DartifactId = my-app Brief groupId equivalent of your organization, as org.springframework, will be converted to the corresponding, local path artifactId, you have the main jar package name, that is, you have beaten the name of the jar. To compile application resources mvn compile Compiling the corresponding test class jave file is compiled and run test class mvn test If you want to compile test class to run test, the implementation of mvn test-compile Packaging and installation of your local library Package: mvn package Installation: mvn install Create a web site: mvn site Clear all output: mvn clean Ide to create the relevant file mvn idea: idea or mvn eclipse: eclipse

By the way, maven2 is a life-cycle concept, meaning that if you are running package, the corresponding previous steps, such as compile, test and so will automatically. The beginning of the implementation would be more slow and therefore require a remote database from the maven2 to download all the files to the local. If you are local there is no corresponding dependence on packet, then the time will go to a remote maven to download, so to configure an image library is more important.

maven configuration chapter of the settings.xml maven2 configuration file mainly concentrated in the pom.xml and settings.xml. First it said the settings.xml, settings.xml for maven is the equivalent of overall configuration, used for all projects. The maven2 exist two settings.xml, one in maven2 installation directory conf the following as the overall configuration. For the team setting, the definition of consistency is the key, so maven2/conf following settings.xml as a team on a common configuration file. Ensure that all team members have the same configuration. Of course, for each member, we need a special custom settings, such as user information, so another one settings.xml on as a local configuration. The default location: $ (user.dir) / .m2/settings.xml directory ($ (user.dir) refers to windows in the user directory). settings.xml basic structure is as follows:

A brief look at the configuration of several major factors: localRepository: said location to save the local library, which is the main maven2 save jar location, the default in the $ (user.dir) / .m2/repository, if you need another set, they replace the other path. offline: If you do not want to compile every time, have to go find a remote central repository, it is set to true. Of course, the premise is that you have already downloaded the necessary dependency packages. Servers: The distributionManagement element in the POM defines the development of libraries. However, the specific username and pwd can not be used in the pom.xml, so to save the server through this configuration information

id: server's id, used to match distributionManagement database id, more important. username, password: used to login to this server's user name and password privateKey, passphrase: set the private key, and passphrase filePermissions, directoryPermissions: When the library file or directory is created, you need permission to visit. The light of unix file permissions, such as the 664 and 775 Mirrors: Mirror said the library, specify the database mirroring, used to increase the other libraries

id, name: the only sign used to distinguish between the mirror url: mirror url mirrorOf: This image points to the service id Proxies: mainly used in the library can not be direct access to the central user profile.

id: Agent logo active: whether the activation agent protocol, host, port: protocol: / / host: port proxy username, password: user name and password nonProxyHosts: no proxy host Profiles: The profile is similar to pom.xml elements include activation, repositories, pluginRepositories and properties elements in the beginning of contact, it may be more confusing, this is actually maven2 of the more powerful functions. Literally speaking, is the personality configuration. After a separate profile definition, and will not enter into force, by meeting the conditions to activate. repositories, and pluginRepositories The definition of other development libraries and library plug-in development. For the team, it certainly has its own development library. This configuration can be defined. The following configuration, defines a local development bank, for release release.

releases, snapshots: for each product version of the Release or snapshot (Note: release and the snapshot of the difference between, release version is generally more stable, while the snapshot is basically unstable, only as a snapshot)

properties: maven of the properties as a placeholder value, such as the ant's properties. Includes the following 5 types of values: 1. Env.X, returns the current environment variables 2. Project.x: Back pom defined in the element values, such as project.version 3. Settings.x: Back to the elements defined in settings.xml 4. Java system property: All After java.lang.System.getProperties () Returns the value of the 5. X: set the value of the user's own Activation: used to activate this profile

jdk: If you match the specified jdk version, will be activated os: operating system property: If maven can detect the corresponding attribute file: the file is used to determine the existence or non-existent

In addition to using activation to activate the profile, can also be activated by activeProfiles ActiveProfiles That activated profile, through the profile id to specify.

<activeProfiles>
<activeProfile>env-test</activeProfile> Specifies the id of the profile
</activeProfiles>

pom as a project object model. Xml indicated by maven project, use the pom.xml to achieve. Mainly describes the project: including the configuration file; developers need to follow the rules, the defect management system, organization and licenses, the project url, project dependencies, as well as all the other project-related factors. Quick View:

Basic elements: POM includes all the project information. maven-related: pom defines the smallest maven2 elements, allowing groupId, artifactId, version. All the required elements of groupId: project or organization's unique identifier, and the configuration, the resulting path could result from the generation, such as the relative path org.codehaus.mojo build: / org / codehaus / mojo artifactId: the common name of the project version: the version of the project packaging: packaging of mechanisms, such as pom, jar, maven-plugin, ejb, war, ear, rar, par classifier: classification POM relationship: Is mainly dependent on, inheritance, synthesis dependency relations:

groupId, artifactId, version: description of the project rely on the only sign may be installed in the following ways: Use the following command to install: · Mvn install : install-file-Dfile = non-maven-proj.jar-DgroupId = some.group-DartifactId = non-maven-proj-Dversion = 1 Create your own libraries, and configuration, use the deploy: deploy-file * Set this depends range system, define a system path. Is not recommended. type: the corresponding forms of reliance on product packages, such as jar, war scope: to limit the scope of the corresponding dependence, including the following several variables: · Compile : the default scope, used by the compiler provided: similar to compile, but the support you expect jdk or containers provided, similar to the classpath · Runtime : in the implementation, the need to use the test: used to test the use of the task system: need to get outside to provide the corresponding element. To get through the systemPath systemPath: only for the range of system. Provide the appropriate path optional: marked optional, when the project is also dependent on their own time. For the continuous use of exclusive reliance on external maven tell you only the specified items, not including related dependency. This version of the main factors used to resolve conflicts

packaging type of pom for the parent and the need for synthesis of multiple projects. We need to increase the value of corresponding to the parent pom, for subprojects inherit. The main elements are as follows: Dependent developers and collaborators list of plug-in implementation of plug-ins list of statements using the appropriate matching ids Plug-in configuration sub-project configuration

build setting is mainly used to compile settings, including the two main elements, build, and report build Is divided into two parts, the basic elements and extend elements of a collection of note: including project build and profile build

defaultGoal: define a default target, or stage. Such as the install directory: the directory to compile the output finalName: the style of the final document is generated filter: Definition filter, used to replace the corresponding properties file, use the maven-defined properties. Set the value of all placehold

Resources (resources) You need to specify the project resources. Such as the spring configuration file, log4j.properties

resources: resource list, including all the resources used for targetPath: specify the target path, for the placement resources for build filtering: whether to replace the properties of resources placehold directory: the location of resources includes: styles, including those resources excludes: exclude resources testResources: test resource list of plug-in build, the implementation of the plug-in, more useful parts, such as using jdk 5.0 compiler, etc.

extensions: true or false, whether the load plug-in extensions. Default false inherited: true or false, whether this plug-in configuration will be used in poms, who inherited this project configuration: specify the plug-in configuration dependencies: plug-ins need to rely on the package executions: used to configure the execution objectives, a plug-in can have multiple targets. Are as follows:

Description: id: a unique identifier that provides execution goals: the target phase: that stage, the objective would be at what stage in the implementation of inherited: and the above elements, as set false maven will be refused to implement the succession to the sub plug-ins configuration: indicates that this implementation of the configuration properties

Plugin Manager pluginManagement: plug-in manager in the same way, including plug-in element, is used in a specific project configuration. All subprojects inherit this project can use. The main elements of the definition of a common plug-ins

Expansion of the main elements of the collection include the following elements: Directories Used to set up a variety of directory structure, as follows:

Distribution Management The distribution for configuration management, configuration corresponding product release information, and is mainly used for publishing, said after the implementation of the mvn deploy the location you want to publish One configuration to the file system

Use maven2 for the team to configure it for the team, the establishment of a unified development environment is necessary, but maven could very well help to establish a unified environment. Here's how to more effectively carry out a unified configuration. Preparation: Download the necessary software: maven2: http://maven.apache.org/download.html the most important maven-proxy: to proxy repository, using a proxy to access multiple remote repository http://maven-proxy.codehaus.org/ continuum: a nice continuous integration tool for automated build. Support for ant, maven http://maven.apache.org/continuum/ svn: version control tool

To create a consistent development environment

In a shared development environment, a better proposal is to maintain the maven of the two different configuration files to be administered separately, including the sharing and user-defined settings. Common configurations included in the installation directory, but separate development settings are saved in the user's local directory.

Includes the following shared factors: A typical server settings are common, only the user name needs to set the user environment. The use of consistent definitions to configure the settings common profile defines the common elements, the internal development of libraries, including the designation of the organization or department released products. These libraries are independent of the core development libraries. Activation profiles list, used to activate the corresponding profile plugin group only if your organization has its own plug-ins defined for the command line to run is defined in the pom. For individual users, set up as follows:

Most organizations create a shared development libraries will create their own internal development libraries for the configuration, the center development library for connecting to maven Set up the internal development library is simple, using http protocol, you can use existing http server. Or create new services, the use of apache, or the jetty Suppose the server address of 192.168.0.2, port 8080 http://192.168.0.2:8080/repo-local Set another developer library, used to set the project snapshot repository http://192.168.0.2:8080/repo-snapshot Center image library, use the maven-proxy creation, of course, you can create your own image. Used to download the artifact is not a local library

maven-proxy settings from the Internet directly to download maven-proxy-standalone-0.2-app.jar and proxy.properties In the command line, direct run java-jar maven-proxy-standalone-0.2-app.jar proxy.properties The main configurations: Set repo.list added to the appropriate library on the can, the following definition: repo.list = repo1.maven.org, ... # maven's central repository repo.repo1.maven.org.url = http://repo1.maven.org/maven2 repo.repo1.maven.org.description = maven.org repo.repo1.maven.org.proxy = one repo.repo1.maven.org.hardfail = false repo.repo1.maven.org.cache.period = 360000 repo.repo1.maven.org.cache.failures = true After all of the remote database, to increase through this way. By the way, do not forget to note the original example, it is no way to visit.

Organization to create a standard pom The definition of common elements, including the company's structure, such as the organizational, departmental and team. Look at what maven itself can serve as a good reference. Such as the scm

For the project itself, the parent pom rarely updated. Therefore, the final way to save the parent pom file in a separate version of the control area, they can check out, change and configuration.

Lasting integration of the use of Continuum

Continued integration of auto-build your project, through a certain time, including all of the conflicts in the early detection, rather than the release time. Also continuing the development of integration is also a good way, so that team members can produce subtle, interactive changes to more effectively support parallel development process. You can use maven as a lasting integration of the continuum of services. Installation continuum, relatively simple, use the following command: C: \ mvnbook \ continuum-1.0.3> bin \ win32 \ run Can http://localhost:8082/continuum to verify in order to support the continuum Send e-mail reminders, you will need the appropriate smtp service for sending messages. Default to localhost: 25, if you do not set up, edit the file above to change the smtp-host setting. Next, set the svn directory: svn co http://www.cnblogs.com/flyingzqx/admin/file:///C:/mvnbook/svn/proficio/trunk proficio Edit pom.xml to get the correct corresponding e-mail address.

If you return to http://localhost:8082/continuum, you will see a corresponding list of items.

Once you are logged in, you can choose mavan 2.0 project to increase the corresponding projects. You can add your url or submit your local content.

You can use the local pom url, as follows http://www.cnblogs.com/flyingzqx/admin/file:///c:mvnbook/proficio/pom.xml

After this url submission, continuum will return to the success of the corresponding information. The following principles to better contribute to the sustainability integration: As early as submitted, are always present: When a user regularly submitted to the constant integration is most effective. This does not mean that the author is not the correct code. Regular running build: for the failure to detect the earliest amendments were defeated as soon as possible: When the failure occurred, it should be immediately amended version of the failure of the proposed operation of an effective clean build Running a complex integrated test build all of the project's structure continued to run the project copy the branch

Related Posts of maven2 use Xiangjie

In some special circumstances, we may be saved in the database connection information config.properties document, for example, make a install.jsp to modify config.properties documents, implementation of online information on the database configuration. At

If you do not want to use the default hibernate.cfg.xml file as a configuration file, we can also specify the configuration file name: File file = new File ( "C: \ \ myhibernate.xml"); Configuration config = new Configuration (). Configure (file

1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to understa