Maven introduction configuration and nexus private server construction

Maven is a 基于项目对象模型(POM)用于进行项目的依赖管理、生命周期管理tool software with
core functions:

  • Depend on jar package management
  • Project life cycle management
  • Polymer engineering

Installation configuration

Maven is developed based on Java language and therefore relies on JDK (JDK1.7+ recommended)

  1. Download maven: official website , Baidu network disk

  2. No installation required, unzip, ready to use out of the box
    Directory structure:

    • bin stores instruction files (Maven provides an mvn instruction)
    • boot contains a jar file of a class loading framework
    • conf contains Maven’s core configuration file settings.xml
    • lib stores the jar files required for maven to run
  3. Configure environment variables

Project structure

project (project name)
– src
– main (storing the source files of the project)
– java (storing java code, equivalent to the src directory in traditional projects)
– resources (storing configuration files and static resource logs, equivalent to transferring projects web directory)
– test (storage the unit test code of the project)
– pom.xml

Project dependency management

process

  1. Configure dependencies in pom.xmI in the project
  2. maven reads the pom.xml of the project
  3. Maven checks whether the local warehouse has the jars required by the project, and if so, it is directly introduced into the project.
  4. If the local warehouse does not have the dependencies required by the project, maven will connect to the remote warehouse to download (grid)
  5. Maven first saves the jar file downloaded from the remote warehouse to the local warehouse, and then references it from the local warehouse to the project.

Warehouse introduction

  • 本地仓库: It is a folder on the local computer (can be any customized folder)
  • 远程仓库
    • 中央仓库: The official warehouse provided by maven, including all required dependencies (no configuration required)
    • 公共仓库: Third-party warehouses other than the central warehouse are public warehouses, such as aliyun (configuration required)
    • 私服: Maven warehouse built by the enterprise for internal use

Insert image description here

Maven warehouse configuration

/conf/settings.xmlConfigure in

  • Configure local warehouse
    <localRepository>D:\software\install\apache-maven-3.8.1\repo</localRepository>
    
  • Configure public repository
    <mirrors>
    	<mirror>
    		<id>nexus-aliyun</id>
    		<mirrorOf>central</mirrorOf>
    		<name>Nexus aliyun</name>
    		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
    	</mirror>
    </mirrors>
    
  • Configure private server

private server

The company builds a Mawen warehouse for internal use

  • Developers need to rely on downloading directly from private servers
  • Private servers can realize the sharing of internal dependencies within the enterprise: when an enterprise develops a common plug-in (jar), it can be published to the private server, and other developers who can connect to the current private server can share this plug-in.

Private server construction

We can build private servers through the specialized Maven warehouse management software. For example: Apache Archiva, Nexus

  1. Download Nexus: Baidu Cloud Disk
  2. Unzip Nexus
  3. Install and run
    1. Enter nexus-2.14.5-02/bindirectory
    2. Open the cmd command line as an administrator and execute the command
      Insert image description here
  4. Login nexus
    1. Start nexus
    2. Open the browser: http://localhost:8081/nexus
    3. Click on the upper right corner Log InAccount: admin Password: admin123
  5. Warehouse type
    • group: Not a specific warehouse, but a warehouse group (logical)
    • hosted: Storage dependent files (physical) in private servers
    • proy:Agent warehouse, representing a central warehouse/public warehouse (logical)

Configure proxy warehouse

Insert image description here
Insert image description here

Configure private server

settings.xmlIn the servers tag of the maven file

<!-- 配置连接私服所需的帐号和密码 -->
<servers>
	<server>
		<id>nexus-public</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
</servers>
<!-- repository 和 pluginRepository 的 id 子标签的值,要和上面配置的scrver的id子标签的值一致 -->
<profiles>
	<profile>
		<id>nexus</id>
		<repositories>
			<repository>
				<id>nexus-public</id>
				<name>nexus release snapshot repository</name>
				<url>http://192.168.10.125:8081/nexus/content/groups/public/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>true</enabled></snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>nexus-public</id>
				<url>http://192.168.10.125:8081/nexus/content/groups/public/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>true</enabled></snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
</profiles>
<!-- activeProfiles配置激活profile -->
<activeProfiles>
	<activeProfile>nexus</activeProfile>
</activeProfiles>

Guess you like

Origin blog.csdn.net/weixin_55556204/article/details/125386396