Pom configuration instructions

Source: Internet
Author: User

What is Pom?
Pom serves as the project object model. The Maven project is represented in XML and implemented using Pom. xml. It mainly describes projects, including configuration files, rules to be followed by developers, defect management systems, organizations and licenses, project URLs, project dependencies, and all other project-related factors.
Quick View:
<Project>
<Modelversion> 4.0.0 </modelversion>

<! -- The basics -->
<Groupid>... </groupid>
<Artifactid>... </artifactid>
<Version>... </version>
<Packaging>... </packaging>
<Dependencies>... </dependencies>
<Parent>... </parent>
<Dependencymanagement>... </dependencymanagement>
<Modules>... </modules>
<Properties>... </Properties>

<! -- Build settings -->
<Build>... </build>
<Reporting>... </reporting>

<! -- More project information -->
<Name>... </Name>
<Description>... </description>
<URL>... </URL>
<Inceptionyear>... </inceptionyear>
<Licenses>... </licenses>
<Organization>... </organization>
<Developers>... </developers>
<Contributors>... </contributors>

<! -- Environment settings -->
<Issuemanagement>... </issuemanagement>
<Cimanagement>... </cimanagement>
<MailingLists>... </MailingLists>
<SCM>... </SCM>
<Prerequisites>... </prerequisites>
<Repositories>... </repositories>
<Pluginrepositories>... </pluginrepositories>
<Distributionmanagement>... </distributionmanagement>
<Profiles>... </profiles>
</Project>

Basic Content:
Pom includes all project information.
Maven:
Pom defines the smallest maven2 element and allows groupid, artifactid, and version. All required elements

Groupid: the unique identifier of a project or organization. The path generated during configuration is also generated. For example, the relative path generated by org. codehaus. mojo is/org/codehaus/mojo.
Artifactid: general name of the project
Version: version of the project.
Packaging: Packaging mechanism, such as pom, jar, Maven-plugin, EJB, war, ear, rar, par
Classifier: Category
Pom relationship:
Mainly dependent, inherited, and merged
Dependency:
<Dependencies>
<Dependency>
<Groupid> JUnit </groupid>
<Artifactid> JUnit </artifactid>
<Version> 4.0 </version>
<Type> jar </type>
<Scope> test </scope>
<Optional> true </Optional>
</Dependency>
...
</Dependencies>

Groupid, artifactid, version: the unique identifier of the dependent project.
You can install it in the following ways:

Run the following command to install:
MVN install: Install-file-dfile = non-maven-proj.jar-dgroupid = Some. Group-dartifactid = non-Maven-proj-dversion = 1
Create and configure your own library, and use deploy: deploy-File
Set the dependency range to system and define a system path. Not recommended.
Type: The corresponding dependent product package format, such as jar and war.
Scope: used to limit the corresponding dependency scope, including the following variables:
Compile: the default range for compiling.
Provided: similar to compiling, but supports the JDK or container, similar to classpath
Runtime: used during execution
Test: used for test tasks
System: the corresponding elements must be provided externally. Obtained Through systempath
Systempath: used only in the range of system. Provide the corresponding path
Optional: The annotation is optional. When the project itself is dependent. Used for continuous dependency
Dedicated
It tells Maven that you only include the specified project, not the relevant dependencies. This factor is mainly used to solve version conflicts.
<Dependencies>
<Dependency>
<Groupid> org. Apache. MAVEN </groupid>
<Artifactid> Maven-embedder </artifactid>
<Version> 2.0 </version>
<Exclusions>
<Exclusion>
<Groupid> org. Apache. MAVEN </groupid>
<Artifactid> Maven-core </artifactid>
</Exclusion>
</Exclusions>
</Dependency>
Indicates that the maven-embedder project requires Maven-core, but we do not want to reference Maven-core.

Inheritance relationship
Another powerful change brought about by Maven is project inheritance. Main settings:
Define Parent Project
<Project>
<Modelversion> 4.0.0 </modelversion>
<Groupid> org. codehaus. Mojo </groupid>
<Artifactid> my-parent </artifactid>
<Version> 2.0 </version>
<Packaging> pom </packaging>
</Project>
Packaging type. Pom is required for parent and merging multiple projects. We need to add the corresponding value to the parent Pom for Child Project inheritance. The main elements are as follows:

Dependent Type
Developer and creator
Plug-in list
Report list
Plug-in execution uses the corresponding matching IDs
Plug-in configuration
Sub-project configuration
<Project>
<Modelversion> 4.0.0 </modelversion>
<Parent>
<Groupid> org. codehaus. Mojo </groupid>
<Artifactid> my-parent </artifactid>
<Version> 2.0 </version>
<Relativepath> ../My-parent </relativepath>
</Parent>
<Artifactid> my-project </artifactid>
</Project>
Relativepath is not required, but used to specify the directory of the parent for quick query.

Dependencymanagement:
It is used to configure the common dependencies of parent projects. It mainly configures the same factors of dependency packages, such as version and scope.

Merging (or multiple modules)
A project has multiple modules, also called multiple modules, or a merging project.
The following definition:
<Project>
<Modelversion> 4.0.0 </modelversion>
<Groupid> org. codehaus. Mojo </groupid>
<Artifactid> my-parent </artifactid>
<Version> 2.0 </version>
<Modules>
<Module> my-project1 <module>
<Module> my-project2 <module>
</Modules>
</Project>

Build settings
It is mainly used for compilation settings, including two main elements: Build and report.
Build
It consists of two parts: basic elements and extended element sets.
Note: including Project Build and profile build
<Project>
<! -- "Project Build" contains more elements than just the basebuild set -->
<Build>... </build>
<Profiles>
<Profile>
<! -- "Profile build" contains a subset of "Project Build" s elements -->
<Build>... </build>
</Profile>
</Profiles>
</Project>

Basic Elements
<Build>
<Defagogoal> install </defaultgoal>
<Directory >$ {basedir}/Target </directory>
<Finalname >$ {artifactid}-$ {version} </finalname>
<Filters>
<Filter> filters/filter1.properties </filter>
</Filters>
...
</Build>

Defaultgoal: defines the default target or stage. For example, install
Directory: directory for compiling and Output
Finalname: generate the final file Style
Filter: defines filtering. It is used to replace the corresponding attribute file and use the attributes defined by Maven. Set all placehold values

Resources)
Resources that need to be specified in your project. Such as the spring configuration file, log4j. Properties
<Project>
<Build>
...
<Resources>
<Resource>
<Targetpath> META-INF/plexus </targetpath>
<Filtering> false </filtering>
<Directory >$ {basedir}/src/main/plexus </directory>
<Shortdes>
<Include> Configuration. xml </include>
</Shortdes>
<Excludes>
<Exclude> **/*. properties </exclude>
</Excludes>
</Resource>
</Resources>
<Testresources>
...
</Testresources>
...
</Build>
</Project>

Resources: resource list, used to include all resources
Targetpath: Specifies the target path, used to place resources, and used to build
Filtering: whether to replace the property placehold in the Resource
Directory: Location of the Resource
Schemdes: styles, including those resources
Excludes: excluded Resource
Testresources: Test resource list
Plug-ins
The plug-ins executed during build, such as compiling with JDK 5.0.
<Project>
<Build>
...
<Plugins>
<Plugin>
<Groupid> org. Apache. Maven. plugins </groupid>
<Artifactid> Maven-jar-plugin </artifactid>
<Version> 2.0 </version>
<Extensions> false </extensions>
<Inherited> true </inherited>
<Configuration>
<Classifier> test </classifier>
</Configuration>
<Dependencies>... </dependencies>
<Executions>... </executions>
</Plugin>
</Plugins>
</Build>
</Project>

Extensions: true or false. Whether to LOAD extension. Default Value: false.
Inherited: true or false, whether the plug-in configuration will be applied to poms, and projects inherited from this
Configuration: Specify the plug-in configuration
Dependencies: the package to which the plug-in depends
Executions: used to configure execution targets. A plug-in can have multiple targets.
As follows:
<Plugin>
<Artifactid> Maven-antrun-plugin </artifactid>

<Executions>
<Execution>
<ID> echodir </ID>
<Goals>
<Goal> RUN </goal>
</Goals>
<Phase> verify </phase>
<Inherited> false </inherited>
<Configuration>
<Tasks>
<Echo> build dir :$ {project. Build. Directory} </echo>
</Tasks>
</Configuration>
</Execution>
</Executions>
</Plugin>
Note:

ID: the unique identifier of the execution.
Goals: indicates the target
Phase: indicates the stage in which the target will be executed.
Inherited: As with the above element, setting false MAVEN will reject the execution of the inheritance to the sub-plug-in.
Configuration: indicates the Configuration Attribute of the execution.

Plugin Management
Pluginmanagement: plug-in management includes Plug-In elements in the same way for configuration in a specific project. All sub-projects that inherit from this project can be used. It mainly defines the common elements of the plug-in.

Extended Element Set
It mainly includes the following elements:
Directories
Used to set various directory structures, as follows:
<Build>
<Sourcedirectory >$ {basedir}/src/main/Java </sourcedirectory>
<Scriptsourcedirectory >$ {basedir}/src/main/scripts </scriptsourcedirectory>
<Testsourcedirectory >$ {basedir}/src/test/Java </testsourcedirectory>
<Outputdirectory >$ {basedir}/target/classes </outputdirectory>
<Testoutputdirectory >$ {basedir}/target/test-classes </testoutputdirectory>
...
</Build>

Extensions

Indicates the plug-in to be extended, which must be included in the corresponding build path.

<Project>
<Build>
...
<Extensions>
<Extension>
<Groupid> org. Apache. Maven. Wagon </groupid>
<Artifactid> wagon-FTP </artifactid>
<Version> 1.0-alpha-3 </version>
</Extension>
</Extensions>
...
</Build>
</Project>

Reporting
Outputs Reports in the site stage. Specific Maven plug-ins can output corresponding custom and Configuration Reports.
<Reporting>
<Plugins>
<Plugin>
<Outputdirectory >$ {basedir}/target/site </outputdirectory>
<Artifactid> Maven-project-Info-Reports-plugin </artifactid>
<Reportsets>
<Reportset> </reportset>
</Reportsets>
</Plugin>
</Plugins>
</Reporting>

Report sets
Used to configure different targets and apply them to different reports.
<Reporting>
<Plugins>
<Plugin>
...
<Reportsets>
<Reportset>
<ID> sunlink </ID>
<Reports>
<Report> javadoc </Report>
</Reports>
<Inherited> true </inherited>
<Configuration>
<Links>
<Link> http://java.sun.com/j2se/1.5.0/docs/api/ </link>
</Links>
</Configuration>
</Reportset>
</Reportsets>
</Plugin>
</Plugins>
</Reporting>

More project information
Name: In addition to artifactid, a project can have multiple names.
Description: Project Description
URL: project URL
Inceptionyear: Founding year

Licenses
<Licenses>
<License>
<Name> Apache 2 </Name>
<URL> http://www.apache.org/licenses/LICENSE-2.0.txt </URL>
<Distribution> repo </distribution>
<Comments> A business-friendly OSS license </comments>
</License>
</Licenses>

Organization
Configure organization information
<Organization>
<Name> codehaus mojo </Name>
<URL> http://mojo.codehaus.org </URL>
</Organization>

Developers
Configure developer information
<Developers>
<Developer>
<ID> Eric </ID>
<Name> Eric </Name>
<Email> eredmond@codehaus.org </Email>
<URL> http://eric.propellors.net </URL>
<Organization> codehaus </organization>
Http://mojo.codehaus.org <organizationurl> </organizationurl>
<Roles>
<Role> effecect </role>
<Role> developer </role>
</Roles>
<Timezone>-6 </timezone>
<Properties>
<Picurl> http://tinyurl.com/prv4t </picurl>
</Properties>
</Developer>
</Developers>

Contributors
<Contributors>
<Contributor>
<Name> Noelle </Name>
<Email> some.name@gmail.com </Email>
<URL> http://noellemarie.com </URL>
<Organization> Noelle Marie </organization>
Http://noellemarie.com <organizationurl> </organizationurl>
<Roles>
<Role> tester </role>
</Roles>
<Timezone>-5 </timezone>
<Properties>
<Gtalk> some.name@gmail.com </Gtalk>
</Properties>
</Contributor>
</Contributors>

Environment Settings

Issue management
Define related bug tracking systems, such as Bugzilla, testtrack, and ClearQuest.
<Issuemanagement>
<System> Bugzilla </system>
<URL> http: // 127.0.0.1/Bugzilla </URL>
</Issuemanagement>
Continuous Integration Management
Continuous integrated management, based on triggers or timings
<Cimanagement>
<System> continuum </system>
<URL> http: // 127.0.0.1: 8080/continuum </URL>
<Notifiers>
<Notifier>
<Type> mail </type>
<Sendonerror> true </sendonerror>
<Sendonfailure> true </sendonfailure>
<Sendonsuccess> false </sendonsuccess>
<Sendonwarning> false </sendonwarning>
<Configuration> <address> continuum@127.0.0.1 </address> </configuration>
</Notifier>
</Notifiers>
</Cimanagement>

Mailing lists
<MailingLists>
<Mailinglist>
<Name> User List </Name>
<Subscribe> user-subscribe@127.0.0.1 </subscribe>
<Unsubscribe> user-unsubscribe@127.0.0.1 </Unsubscribe>
<Post> user@127.0.0.1 </post>
<Archive> http: // 127.0.0.1/user/</archive>
<Otherarchives>
<Otherarchive> http://base.google.com/base/1/127.0.0.1 </otherarchive>
</Otherarchives>
</Mailinglist>
</MailingLists>

SCM
Software Configuration Management, such as CVS and SVN
<SCM>
<Connection> SCM: SVN: http: // 127.0.0.1/SVN/My-project </connection>
<Strong connection> SCM: SVN: https: // 127.0.0.1/SVN/My-project </strong connection>
<Tag> head </Tag>
<URL> http: // 127.0.0.1/websvn/My-project </URL>
</SCM>

Repositories

Configure the same as the development library in setting. xml.

Plugin Repositories
Configure Repositories

Distribution Management
It is used to configure Distribution Management and Product release information. It is mainly used for publishing. After MVN deploy is executed, it indicates the location to be released.
1. Configure to File System
<Distributionmanagement>
<Repository>
<ID> proficio-repository </ID>
<Name> proficio repository </Name>
<URL> file: // $ {basedir}/target/deploy </URL>
</Repository>
</Distributionmanagement>
2 Use SSH2 Configuration
<Distributionmanagement>
<Repository>
<ID> proficio-repository </ID>
<Name> proficio repository </Name>
<URL> SCP: // sshserver.yourcompany.com/deploy </URL>
</Repository>
</Distributionmanagement>
3 Use SFTP Configuration
<Distributionmanagement>
<Repository>
<ID> proficio-repository </ID>
<Name> proficio repository </Name>
<URL> SFTP: // ftpserver.yourcompany.com/deploy </URL>
</Repository>
</Distributionmanagement>
4. Use external SSH Configuration
The compilation extension is used to specify that your files are provided to the corresponding remote server using the external SSH provided by wagon.
<Distributionmanagement>
<Repository>
<ID> proficio-repository </ID>
<Name> proficio repository </Name>
<URL> scpexe: // sshserver.yourcompany.com/deploy </URL>
</Repository>
</Distributionmanagement>
<Build>
<Extensions>
<Extension>
<Groupid> org. Apache. Maven. Wagon </groupid>
<Artifactid> wagon-ssh-External </artifactid>
<Version> 1.0-alpha-6 </version>
</Extension>
</Extensions>
</Build>

5. Use FTP to configure
<Distributionmanagement>
<Repository>
<ID> proficio-repository </ID>
<Name> proficio repository </Name>
<URL> ftp://ftpserver.yourcompany.com/deploy </URL>
</Repository>
</Distributionmanagement>
<Build>
<Extensions>
<Extension>
<Groupid> org. Apache. Maven. Wagon </groupid>
<Artifactid> wagon-FTP </artifactid>
<Version> 1.0-alpha-6 </version>
</Extension>
</Extensions>
</Build>

Repository corresponds to your development library. User information is obtained through the server in settings. xml

Profiles
Similar to profiles in settings. XML, the following style is added:
<Profiles>
<Profile>
<ID> test </ID>
<Activation>... </activation>
<Build>... </build>
<Modules>... </modules>
<Repositories>... </repositories>
<Pluginrepositories>... </pluginrepositories>
<Dependencies>... </dependencies>
<Reporting>... </reporting>
<Dependencymanagement>... </dependencymanagement>
<Distributionmanagement>... </distributionmanagement>
</Profile>
</Profiles>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.