Home  >  Article  >  Java  >  Use nexus to build a LAN private server

Use nexus to build a LAN private server

零下一度
零下一度Original
2017-07-23 15:00:282876browse

Using nexus to build a LAN private server

1. Understanding the maven warehouse

1.1 The role of the maven warehouse

I think back to the time when maven was not used before, we used the original project skeleton of eclipse When building a project, there is often a lib folder in the project directory to store the jar files required for the project. Every time a new project is built, there will be such a lib folder. Then copy the jar into the lib folder configuration path. Obviously there is a lot of repeated work, and the jar packages used in different projects are different, so we need to slowly distinguish them. Then we used project management tools such as svn or git, and we needed to introduce a large number of jar files into the code base, which was not very appropriate.
 Maven can help us solve these problems. The maven warehouse is a location specifically used to store jar files (it can also be used to store project war, zip, pom and other files). Each jar file is assigned a coordinate in the maven warehouse, such as the jstl jar package:

<groupid>javax.servlet</groupid>        组ID
<artifactid>jstl</artifactid>           构建ID
...  其余属性后续介绍

In this way, maven can easily control the project dependency version. Simply put, the maven warehouse helps us manage project components in a unified manner.

1.2 Maven warehouse classification

Use nexus to build a LAN private server##  The query path of project construction: first query the local warehouse, if not found, the central warehouse will be queried, if not found, an error will be reported. The central warehouse address is:

  1. Private server nexus uses

  2. . It is recommended to use the

  3. above. Three are more common and are used more often in projects. However, due to the slow download speed and incomplete jar files in the warehouse, actual enterprise development requires us to build a private server warehouse.

    2. Install and use nexus

     Note here that building a maven private server is not just a tool. The version used by the blogger is nexus-2.12.0.


  4. Click to download, password: 1ar1

  5. Unzip after downloading is complete Yes, after decompression is completed, you can see it in the directory nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin\jsw:

    Use nexus to build a LAN private server

  6. ## The blogger's computer is 64-bit, so open the last folder:

  7. Use nexus to build a LAN private server

  8. Click on the second bat file to set it as a windows service, open nexus and visit the URL: http: //localhost:8081/nexus/ opens the following page after startup, which means nexus is installed and started successfully.
  9. Use nexus to build a LAN private server3. Configure maven private server

  10. #Click Login in the upper right corner to log in

    . The initial account is admin and the password is admin123. It can be modified after successful login. You can find your account password yourself.

  11. Click on the navigation Respositories

    on the left.
    Use nexus to build a LAN private server

  12. You can see that there are some warehouses by default. The meaning of warehouse type Type:

    hosted host warehouse, used Publish some components that are not allowed by third parties, such as jar packages of commercial software such as Oracle drivers
  • proxy proxy remote warehouses, such as the three maven remote warehouses written above. If certain jar files do not exist locally, they will be downloaded from these proxy sites.
  • releases The release warehouse of the release module in the internal module
  • snapshots The warehouse where the internal snapshot module is released
  • 3rd party is a third-party dependent warehouse. After uploading the jar package locally, use the
  • group warehouse to add other warehouses to facilitate developers to set up
  • Start building the private server warehouse. It is worth noting: maven project index: the maven project index is used to facilitate the search for related dependency builds on the private server site. Therefore, before building a private server, you should download the maven index, which is about tens of MB:


Use nexus to build a LAN private serverChange the Download Remote Indexes property to True, and then click save. You can view it in the menu bar Scheduled Tasks The progress of downloading the index.

3.

Add your own proxy remote library
, sometimes our project needs to introduce some special jar files, such as some jar packages of Jboss. At this time, we can also proxy the remote warehouse in the private server. :
Use nexus to build a LAN private serverClick add to add the proxy type, fill in the id, name and url in order. In this case,

no longer needs to be configured in the project

Remote warehouse:

<repository>
    <id>jboss</id>
    <name>JBoss Repository</name>
    <url>;/url>
    <releases>
        <updatepolicy>daily</updatepolicy><!-- never,always,interval n -->
        <enabled>true</enabled>
        <checksumpolicy>warn</checksumpolicy><!-- fail,ignore -->
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <layout>default</layout>
</url></repository>

4.Use nexus to build a LAN private server的使用,上面提到的一些特殊的商业性质相关的jar文件,比如oracle的驱动包,ojdbc.jar并不支持远程下载,这时候可以将我们本地下载好的jar包上传到私服。
Use nexus to build a LAN private server

注意GAV设置要与你pom.xml中一致,上传后添加到Artifacts点击上传即可:
Use nexus to build a LAN private server2
5.由于私服仓库数量过多,导致配置复杂度提高,所以需要用到上述的group类型仓库:
Use nexus to build a LAN private server

切记点击刷新,刷新后点击唯一的一个group仓库,点击配置Configuration就可以看到刚才我们手动添加的代理仓库,然后将代理仓库添加到组仓库,这样依赖,项目中之需要配置组仓库的url就可以访问多个私服仓库。

四. 局域网使用maven私服

4.1 单个项目使用maven私服

在上述步骤完成后,即可在项目中引用私服,pom.xml中改变默认下载仓库url:
指定私服仓库,我的ip是170,不要全盘复制

<repositories>  
    <repository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </repository>  
</repositories>

指定插件仓库

<pluginrepositories>  
    <pluginrepository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </pluginrepository>  
</pluginrepositories>

配置好之后就可以从私服下载依赖包了。但是这种方式只能在改项目中起作用,每次配置项目都需要写两遍,为了将懒人模式进行到底,我们还可以指定全局的私有仓库。

4.2 全局指定私服

找到maven文件的中的Use nexus to build a LAN private server文件
Use nexus to build a LAN private server

在Use nexus to build a LAN private server中添加配置:
在profiles

>标签下添加

<profile>
    <repositories>
        <id>central</id>
        <name>central</name>
        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>
        <layout>default</layout>
        <releases>
            <enabled>true<enabled>
        </enabled></enabled></releases>
        <snapshots>
            <enabled>true<enabled>
        </enabled></enabled></snapshots>
    </repositories>
</profile>

配置好之后激活profile

<activeprofiles>  
    <activeprofile>central</activeprofile>  
</activeprofiles>

这样一来,这台电脑上所有maven项目下载jar文件时都会先访问局域网170的电脑。

-----------------------------------windows配置私服完毕-----------------------------------

扩展:setting,xml中各标签的意义

  1. servers(服务器)

<servers>
    <server>
        <id>server001</id>
        <username>my_login</username>
        <password>my_password</password>
        <privatekey>${usr.home}/.ssh/id_dsa</privatekey>
        <passphrase>some_passphrase</passphrase>
        <filepermissions>664</filepermissions>
        <directorypermissions>775</directorypermissions>
        <configuration></configuration>
    </server>
</servers>

id与pom.xml中distributionManagement的id保持一致,服务器标识
username和password表示服务器认证需要的用户民和密码
privateKey, passphrase一组密钥 (不常用)
filePermissions, directoryPermissions如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(不常用)

2.mirrors(镜像)

<mirrors>
    <mirror>
        <id>planetmirror.com</id>
        <name>PlanetMirror Australia</name>
        <url>;/url>
        <mirrorof>central</mirrorof>
    </url></mirror>
</mirrors>

设置一个中央仓库的镜像,看仓库分类,也是远程仓库的一种配置方式。

3.profiles(构建环境)
这个可能比较难理解,maven权威指南一书中这样说:

  Profile能让你为一个特殊的环境自定义一个特殊的构建;
  构建环境的两个例子是产品环境和开发环境。当你在开发环境中工作时,你的系统可能被配置成访问运行在你本机的开发数据库实例,而在产品环境中,你的系统被配置成从产品数据库读取数据。Maven能让你定义任意数量的构建环境(构建profile),这些定义可以覆盖pom.xml中的任何配置。

简单理解就是你可以先profile中先构件好项目运行的环境,比如预设了A环境实在开发中使用,而实际上线是B环境,那么在上线的时候我们不需要一个个修改pom.xml中的配置,只需要激活改profile即可。

4.activation(激活构建环境 )

<activation>
    <activebydefault>false</activebydefault>
    <jdk>1.5</jdk>
    <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
    </os>
    <property>
        <name>mavenVersion</name>
        <value>2.0.3</value>
    </property>
</activation>

指定profile中配置的环境在什么时候开始生效

5.activeProfiles(激活了的profile)

<activeprofiles>
<activeprofile>env-test</activeprofile>
</activeprofiles>

在Use nexus to build a LAN private server最后的一个标签,表示env-test这个profile已被激活

The above is the detailed content of Use nexus to build a LAN private server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn