Depth discussions with Maven remote repository configuration and deployment

Maven remote repository configuration and deployment

Preface:

Maven is dedicated to building the management tools and Java-related projects. Maven is a project management and integration tools. Maven provides a complete building life cycle framework for developers. Development team almost do not spend much time will be able to automatically complete basic engineering build configuration, because Maven uses a standard directory structure and a default build lifecycle.

Maven's primary purpose is to provide developers: a reusable, maintainable, integrated engineering model easier to understand; with this plug-in or tool model interaction.

Today to share with everyone together to explore is Maven remote repository configuration and deployment, enter the following topic put together

First, the remote repository configuration

In normal development, we often do not use the default central repository, the default speed access to the central warehouse slower, perhaps a lot of people visit, and sometimes can not meet the needs of our project, the project may require certain components of the central the warehouse is not, but there are other remote repository, such as JBoss Maven repository. In this case, the repository may be configured in pom.xml, as follows:





















url: the address points to the warehouse, in general, are based on the address http protocol, Maven users can open the browser component warehouse address in the browser.
releases and snapshots: used to control the release Maven download rights for members and snapshots members. Note that enabled child element, this example releases of enabled is true, expressed open support JBoss warehouse version download release, and snapshots are enabled is false, meaning close JBoss warehouse snapshot version of the download support. According to this configuration, Maven will download the release from the JBoss warehouse components, rather than downloading a snapshot version of the component.
layout: element values indicate default layout is the default layout of the warehouse and Maven3 Maven2, not Maven1 layout. The basic layout will not be used Maven1 of.
Other: For snapshots and releases, in addition to Enabled, which further comprises two additional sub-elements and updatePolicy checksumPolicy.
1: updatePolicy element arranged to check for updates Maven warehouse frequency from a distance, the default value is daily, showing Maven checked once a day. Other useful values include: never- Never check for updates; always- every build check for updates; interval: X- update check every X minutes (X is an arbitrary integer).
2: Policy Configuration Maven check the checksum file elements checksumPolicy used. When the build is deployed to the Maven repository, will test and deploy the corresponding file. When downloading member, Maven file and verifies the checksum, if the checksum verification fails, when the default value checksumPolicy The warn, Maven warning message is output when executed constructed, other available values include: fail-Maven let checksum error encountered fails to build; ignore- Maven completely ignore the checksum error.
Second, the remote repository certification

Most of the remote repository does not require certification, but if it is their own internal use, for safety reasons, or to configure the authentication information.

Configuring authentication information and configuring different remote repository, a remote repository can be configured in pom.xml directly, but the authentication information must be configured in settings.xml file. This is because the pom tend to be submitted to the code repository accessible by all members, but settings.xml generally exists only in the machine. Therefore, in the settings.xml configuration more secure authentication information.

<Settings>
...
<-! Configure Remote Authentication Information Warehouse ->
<Servers>
<Server>
<the above mentioned id> Releases </ the above mentioned id>
<username> ADMIN </ username>
<password> admin123 </ password>
</ Server>
</ Servers>
...
</ Settings>
here in addition to the configuration account password, the key is the value of the id, the id keep the same remote repository repository you configured in the pom.xml inside the id, it is this id authentication information to the warehouse configuration linked together.

Third, the deployment artifacts to a remote repository

The purpose of our own is to set up a remote repository can be easily deployed members of our own projects as well as some of the components can not be obtained directly from the outside of the warehouse. So as to when developing for the other team members.

In addition to Maven can compile, test, package of the project, the project will also deploy generated artifacts to a remote warehouse. First, you need to edit the file pom.xml project. DistributionManagement configuration elements, as follows:

<distributionManagement>

<repository>

<id>releases</id>

<name>public</name>

<url>http://59.50.95.66:8081/nexus/content/repositories/releases</url>;

</repository>

<snapshotRepository>

<id>snapshots</id>

<name>Snapshots</name>

<url>http://59.50.95.66:8081/nexus/content/repositories/snapshots</url>;

</snapshotRepository>

</distributionManagement>

Look at the code, from the name to look out the difference, repository represents represents the repository release version (stable version) member, snapshotRepository represents a snapshot version (development test version) warehouse. These two elements need to be configured id, name and url, id uniquely identifies a remote repository, name is for the convenience of people reading, critical url is the address of the warehouse.

Configured to run the command mvn clean deploy, Maven will deploy the project to build the output component corresponding to a remote repository configuration, the current version is a snapshot version if the project is to deploy a snapshot version of the address of the warehouse, otherwise deployed to the release version of the address of the warehouse.

The current project is a snapshot or release version is distinguished by this true.

Will share the java-related articles every day, we can focus my oh

Guess you like

Origin blog.51cto.com/14456091/2426104