windows下使用nexus搭建maven私服

安装nexus

1.下载nexus,解压.我下的是nexus-2.13.0-01,到nexus-2.13.0-01\bin\jsw这个目录下,会发现有很多系统版本的nexus环境.我的电脑是win7 64位系统,根据对应系统,选择对应版本.打开之后,你会看到如下文件:

console-nexus.bat  : 启动nexus服务器,命令窗口关闭后不会驻留在windows服务中

install-nexus.bat  : 将nexus安装成为windows服务,开机时自动启动,个人比较推荐

nexus.bat  : 暂时没有发现这个的用途

start-nexus.bat  : 启动服务

stop-nexus.bat  : 停止服务

uninstall-nexus.bat  : 卸载nexus在windows中的服务

wrapper.exe


2.将nexus安装成windows服务,点击install-nexus.bat,访问http://localhost:8081/nexus/启动后,点击页面右上角的Log In登录.

默认的用户名是admin,密码是admin123.

登录之后,点击左侧的Repositories,右侧会出现一个页面,会有一个Repository的默认列表.Nexus为我们创建了一下主要的Repository:

1、PublicRepositories,这是一个Repository Group,该Repository  Group包含了多个Repository,其中包含了Releases、Snapshots、ThirdParty和Central。

2、3rd party,该Repository即是存放你公司所购买的第三方软件库的地方,它是一个由Nexus自己维护的一个Repository。 

3、Apache Snapshots,看名字你就应该知道这是个什么样的Repository,这是一个代理Repository,即最终的依赖还是得在Apache官网上去下载,然后缓存在Nexus中。

4、Central,这就是代理Maven Central Repository的Repository。

5、Releases,你自己的项目要发布时,就应该发布在这个Repository,他也是Nexus自己维护的Repository,而不是代理。

6、Snapshots,你自己项目Snapshot的Repository。


3.将第三方jar包手动添加到nexus上,这些jar在maven仓库里面没有,所以手动添加.具体的添加方式可以看这个http://jingyan.baidu.com/article/a948d6517b72eb0a2dcd2e2a.html


4. 创建一个Repository Group, 选择Configuration选项卡,Group ID填public-repositories, Group Name 填Public Repositories.

将右侧的3rd party, Central, Releases, Snapshots添加到左侧.

保存.


5.在Repository列表中,选择你创建的Public Repositories, 右键update index,选择下侧的Browse Index, Refresh,就可以看到在第三步中,手动添加进去的jar包

在我们项目中需要手动添加的有:FCKeditor,javaee,rbsp,birt,oracle,coobird,postgresql.


至此,nexus私服搭建成功.下面来说客户端的使用方式.


创建maven项目

1.安装maven,eclipse配置maven, 参照这个来弄就很好了http://jingyan.baidu.com/article/295430f136e8e00c7e0050b9.html


2.创建一个maven project.本来也想找个网址贴上来的.但是没找着我用的这种方式.网上多数是说这里Create a simple project(skip archetype selection)不勾选.不过我习惯勾选,因为懒得看后面那些东西

后面走默认就好了.

创建出来的结构是这样的,webapp文件夹下是空的,里面的lib和web.xml是我们手动添加的.


3.配置maven,Window-->Preferences-->Maven-->User Settings,在右侧选择maven安装里面的setting.xml文件.再更新,点击open file,可以在eclipse中打开settings.xml文件,进行修改.我忘记了Global Settings和User Settins的应用范围.

下面是我自己的settings.xml文件

<?xml version="1.0" encoding="UTF-8"?>


<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at


    http://www.apache.org/licenses/LICENSE-2.0


Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->


<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.home}/conf/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository F:/java-winchance/repository -->
   <localRepository>D:/.m2/repository</localRepository>




  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
	<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
  </pluginGroups>


  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>


  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->


    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
	<server>    
      <id>releases</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>    
    <server>    
      <id>snapshots</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>
  </servers>


  <mirrors>
		<mirror>
			<id>nexus</id>
			<mirrorOf>*</mirrorOf>
			<name>Nexus Mirror</name>
			<url>http://192.168.18.242:8089/nexus/content/groups/public</url>
		</mirror>
		<mirror>
			<id>Nexus2</id>
			<url>http://192.168.18.242:8089/nexus/content/groups/public</url>
			<mirrorOf>public-snapshots</mirrorOf>
		</mirror>
  </mirrors>




  <profiles>
	<profile>   
		<id>nexus</id>   
		<repositories>   
			<repository>
			  <id>public</id>
			  <name>central</name>
			  <url>http://192.168.18.242:8089/nexus/content/groups/public</url>
			  <layout>default</layout>
			  <releases><updatePolicy>always</updatePolicy><enabled>true</enabled></releases>   
			  <snapshots><enabled>true</enabled></snapshots>  
			</repository>   
		</repositories>   
		<pluginRepositories>   
			<pluginRepository>   
			  <id>public</id>   
			  <url>http://192.168.18.242:8089/nexus/content/groups/public</url>   
			  <releases><enabled>true</enabled></releases>   
			  <snapshots><updatePolicy>always</updatePolicy><enabled>true</enabled></snapshots>   
			</pluginRepository>   
		</pluginRepositories>   
	</profile>   
	<profile>   
		<id>public-snapshots</id>   
		<repositories>
			<repository>
			  <id>public-snapshots</id>
			  <name>public-snapshots</name>
			  <url>http://public-snapshots</url>
			  <layout>default</layout>
			   <releases><updatePolicy>always</updatePolicy><enabled>true</enabled></releases>   
			  <snapshots><updatePolicy>always</updatePolicy><enabled>true</enabled></snapshots>  
			</repository>
		</repositories>  
		<pluginRepositories>   
			<pluginRepository>   
				<id>public-snapshots</id>   
				<url>http://public-snapshots</url>   
				<releases><enabled>false</enabled></releases>   
				<snapshots><updatePolicy>always</updatePolicy><enabled>true</enabled></snapshots>   
			</pluginRepository>   
		</pluginRepositories>   
	</profile>		


  </profiles>


  <!--
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
	<activeProfile>public-snapshots</activeProfile>
  </activeProfiles>
  -->
 
</settings>

这里有一些要注意的地方,
    <mirror>
      <id>public-repositories</id>
      <mirrorOf>*</mirrorOf>
      <name>Public Repositories</name>
      <url>http://192.168.110.44:8081/nexus/content/groups/public-repositories/</url>
    </mirror>
在这一段代码里面,id是我们在一.4步骤里面创建的Group ID, name是Group Name, mirrorOf里面填*表示为所有仓库做镜像,你也可以只填一个在url里面,注意到最后的public-repositories与id的值是一致的.不能乱填.
<localRepository>D:/WebTools/Maven/repository</localRepository>
上面这段代码是配置本地仓库地址的.


4.pom.xml配置了全局的settings.xml之后,就不需要在pom.xml里面做镜像私服的配置了.只需要配置我们需要的jar包就可以了.配好pom.xml之后,项目上可能会有个小红×,我们选中项目,右键maven-->update project.这是就会从nexus上下载我们在pom.xml里面配置的jar到本地仓库.如果nexus上没有,它会从互联网上maven仓库中下载到nexus的centre仓库,然后下载到本地仓库.当第二个人在下载时,就是直接从nexus上下载了.就会很快了.

差不多就是这些了.关于在eclipse怎样编译,打包,安装;maven如何手工添加自定义jar包;如何用maven进行单元测试,后面在补充.

一键测试打包

在项目的pom.xml文件中加入如下代码:

  <build>
  	<finalName>STMQV2.0.1</finalName>
  	<pluginManagement>  
        <plugins>  
          <plugin>  
            <groupId>org.eclipse.m2e</groupId>  
            <artifactId>lifecycle-mapping</artifactId>  
            <version>1.0.0</version>  
            <configuration>  
              <lifecycleMappingMetadata>  
                <pluginExecutions>  
                  <pluginExecution>  
                    <pluginExecutionFilter>  
                      <groupId>org.apache.maven.plugins</groupId>  
                      <artifactId>maven-dependency-plugin</artifactId>  
                      <versionRange>[2.0,)</versionRange>  
                      <goals>  
                        <goal>copy-dependencies</goal>  
                      </goals>  
                    </pluginExecutionFilter>  
                    <action>  
                      <ignore />  
                    </action>  
                  </pluginExecution>  
                </pluginExecutions>  
              </lifecycleMappingMetadata>  
            </configuration>  
          </plugin>  
        </plugins>  
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <version>2.4</version>
        </configuration>
      </plugin>
       <plugin>
	        <groupId>org.apache.maven.plugins</groupId>  
	        <artifactId>maven-surefire-plugin</artifactId>
	        <version>2.17</version> 
	        <configuration>
	          <skipTests>true</skipTests>  
	        </configuration>
	    </plugin>
		<plugin>  
		    <groupId>org.apache.maven.plugins</groupId>  
		    <artifactId>maven-dependency-plugin</artifactId>  
		    <version>2.8</version>  
		    <executions>  
		        <execution>  
		            <phase>package</phase>  
		            <goals>  
		                <goal>copy-dependencies</goal>  
		            </goals>  
		        </execution>  
		    </executions>  
		    <configuration>
		    	<outputDirectory>${project.build.directory}/lib</outputDirectory>
		        <includeScope>compile</includeScope>  
		    </configuration>  
		</plugin>
    </plugins>
  </build>
就可以进行一键测试打包了.其中
<skipTests>true</skipTests>  
设置为true表示跳过测试,直接打包,设置为false表示不跳过测试,通过所有单元测试,才能打包.

		        <execution>  
		            <phase>package</phase>  
		            <goals>  
		                <goal>copy-dependencies</goal>  
		            </goals>  
		        </execution>
这段设置表示将依赖包也打进去,

		    <configuration>
		    	<outputDirectory>${project.build.directory}/lib</outputDirectory>
		        <includeScope>compile</includeScope>  
		    </configuration>  
这段表示依赖包存放的地址.

配置完成了,然后我们打包:

在要打包的项目名上,右键,选择run as --> run configurations,选择右侧的Maven Build如图所示:


这样就可以搭好包了.

我们只需要第一次的时候配置,后面就可以直接在项目上右键,run as-->maven build

至此,关于maven的就差不多都掌握了.

1) 安装maven
2)集成eclipse
3)如何创建maven项目
4)在eclipse怎么样编译.打包,安装
5)maven如何手工添加自定义jar包
6)如何用maven进行单元测试
7)如何在私网用Nexus搭建私服.
我们就可以说自己精通maven了.

有一点要注意的是maven的版本问题,目前最新版3.3.9只支持jdk1.7及以上,如果我们使用的是jdk1.6,那么maven就使用3.2.5版本的.



  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
搭建Maven私服可以使用Sonatype Nexus,它是一个功能强大的仓库管理器,可以帮助我们创建和管理Maven私服。下面是基于Nexus搭建Maven私服的详细步骤: 1. 准备环境:首先,确保你已经安装了Java环境,并且可以正常运行MavenNexus软件。 2. 下载和解压缩Nexus软件:从Sonatype官方网站下载最新版本的Nexus软件,并解压缩到合适的目录中。 3. 启动Nexus使用命令行窗口进入Nexus软件的目录,然后执行 `./bin/nexus start` 命令来启动Nexus服务器。 4. 访问Nexus控制台:在浏览器中输入 `http://localhost:8081` 访问Nexus控制台,默认用户名和密码都是 `admin`,登录成功后,可以看到Nexus的管理界面。 5. 创建Maven仓库:在Nexus控制台中,点击左侧菜单的 `Repositories`,然后点击 `Create repository` 来创建新的Maven仓库。根据需要选择 `Hosted repository` 或者 `Proxy repository`,然后填写相应的配置信息,如仓库名称、URL、布局等。 6. 配置Maven项目:在你的Maven项目的pom.xml文件中添加Nexus私服的配置信息,包括ID、URL等,用来指定将Maven构建输出部署到Nexus仓库中。 7. 部署和使用使用 `mvn deploy` 命令将项目打包并部署到Nexus私服中,当其他开发人员或者CI/CD服务器需要下载依赖时,只需要修改项目的settings.xml文件,指定Nexus私服的URL和凭据即可。 8. 其他设置:你还可以在Nexus控制台里进行其他设置,比如用户管理、访问控制、仓库代理等。 总结一下,使用Nexus搭建Maven私服非常简单,只需要几个基本的步骤即可完成。通过搭建Maven私服,我们可以有效地管理和共享项目的依赖包,提升团队的开发效率和项目的可维护性。这对于生产环境中的项目非常重要。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zerlinda_Li

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值