Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed description of the configuration of Maven default central warehouse settings.xml

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Maven default central warehouse settings.xml configuration details", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Maven default central warehouse settings.xml configuration details" bar!

Maven Foundation-default Central Warehouse

When we create a simple Maven project (only need to configure the dependency in pom.xml), run mvn clean install to build the project, we do not need to download any jar manually, it all depends on the existence of the central warehouse, it will be automatically downloaded from the warehouse. The warehouse is defined in ${M2_HOME} / lib/maven-2.0.10-uber.jar. You can find the file\ org\ apache\ maven\ project\ pom-4.0.0.xml, which defines the address of the default central warehouse:

Central Maven Repository Switchboard default http://repo1.maven.org/maven2 false

If you want to override the default address of the central repository, we will use the image here, which is also configured in setting.xml:

... Maven-net-cn Maven China Mirror http://maven.net.cn/content/groups/public/ central...

This means that only central repositories are mirrored. If you want to mirror all repositories, you can change it to: *

Maven configuration details

Maven2 requires far fewer files to configure than maven1, focusing on pom.xml and settings.xml. Let's start with the fact that settings.xml,settings.xml is the equivalent of a global configuration for maven for all projects. There are two settings.xml in maven2, one of which is located under the installation directory conf of maven2 as a global configuration. For team settings, consistent definition is key, so the settings.xml under maven2/conf serves as a common configuration file for the team. Ensure that all team members have the same configuration. Of course, for each member, special custom settings, such as user information, are required, so another settings.xml is used as a local configuration. The default location is in the ${user.dir} / .m2 / settings.xml directory (${user.dir} refers to the user directory in windows).

The basic structure of settings.xml is as follows:

A brief introduction to several major configuration factors:

LocalRepository

Indicates the location where the local library is saved, that is, the main jar location of maven2, which defaults to ${user.dir} / .m2 / repository. If you need to set it otherwise, change it to another path.

Offline

If you don't want to find the remote central library every time you compile, set it to true. Of course, the premise is that you have downloaded the necessary dependency packages.

Servers

The distributionManagement element in POM defines the development library. However, specific username and pwd cannot be used with pom.xml, so server information is saved through this configuration

Server001 my_login my_password ${usr.home} / .ssh/id_dsa some_passphrase 664 775

The id of id:server, which is used to match the distributionManagement library id, is important.

Username, password: username and password used to log in to this server

PrivateKey, passphrase: set private key, and passphrase

FilePermissions, directoryPermissions: access is required when a library file or directory is created. Refer to unix file licenses, such as 664 and 775

Mirrors

Represents a mirror library, specifies the image of the library, and is used to add other libraries

Planetmirror.com PlanetMirror Australia http://downloads.planetmirror.com/pub/maven2 central

Id,name: a unique flag used to distinguish between mirrors

Url: mirrored url

MirrorOf: the service id that this image points to

Proxies

This setting is mainly used for library user configurations that do not have direct access to the center.

Myproxy true http proxy.somewhere.com 8080 proxyuser somepassword * .google.com | ibiblio.org

Id: flag of the agent

Active: whether to activate the agent

Protocol, host, port:protocol://host:port agent

Username, password: username and password

NonProxyHosts: host that does not require an agent

Profiles

Similar to the profile element in pom.xml, it may be confusing when you first come into contact with activation,repositories,pluginRepositories and properties elements, but this is actually a more powerful feature in maven2. Literally, it is personality configuration. When a profile is defined separately, it does not take effect and needs to be activated by meeting the conditions. Repositories and pluginRepositories define other development libraries and plug-in development libraries. For the team, there must be their own development libraries. It can be defined by this configuration. The following configuration defines a local development library for release distribution.

Repo-local Internal Development Library http://192.168.0.2:8082/repo-local true never warn false default repo-local Internal Development Library http://192.168.0.2:8082/repo-local True never warn false default

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

Properties

The properties of maven is used as the placeholder value, such as the properties of ant. Includes the following five types of values:

Env.X, which returns the current environment variable

Project.x: returns the element value defined in pom, such as project.version

Settings.x: returns the elements defined in settings.xml

Java system property: all values returned by java.lang.System.getProperties ()

X: the value set by the user

Activation

Used to activate this profile

False 1.5 Windows XP Windows x86 5.1.2600 mavenVersion 2.0.3 ${basedir} / file2.properties ${basedir} / file1.properties

Jdk: if the specified jdk version is matched, it will be activated

Os: operating system

Property: if maven can detect the corresponding attribute

File: used to determine whether a file exists or does not

In addition to using activation to activate profile, you can also activate it through activeProfiles

Active Profiles

Represents the active profile, specified by profile id.

Env-test designated profile id thank you for reading, the above is the "Maven default central warehouse settings.xml configuration details" of the content, after the study of this article, I believe you on the Maven default central warehouse settings.xml configuration detailed understanding of this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report