安装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: ${user.home}/.m2/repository-->
<localRepository>D:/WebTools/Maven/repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</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).
| 仓库认证(无论是从远程仓库下载构件还是部署构件,需配置的Nexus帐号和密码认证 ),其中id必须与需要认证的仓库id完全一致
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|-->
<server>
<id>public-repositories</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>central</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</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>
-->
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
| -->
<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>
</mirrors>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
| 配置maven的jdk版本-->
<profile>
<id>jdk-1.6</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
</properties>
</profile>
<!-- 下载构件版本信息控制(有镜像存在时,profile中的 url 就无关紧要了,主要控制对快照版本的下载的支持) -->
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<!-- true(下载releases版本的构件),false(不下载) -->
<enabled>true</enabled>
<!-- 从远程仓库检测更新的频率:默认值是 daily(表示每天检测一次),never(从不检测),always(每次构件检测),interval:x(每隔x分钟检测,x为任意整数) -->
<!-- 亦可强制检测更新:命令 clean install-U -->
<updatePolicy>always</updatePolicy>
<!-- 用来配置Maven验证、校验的策略:默认值 warn(执行构件时输出警告信息),fail(遇到校验和错误时就让构件失败),ignore(完全忽略校验和错误) -->
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<!-- true(下载snapshots版本的构件),false(不下载) -->
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
<!-- 激活这个profile,这样我们就可以全局的使用这个配置,不再需要为每个POM做重复的配置了。 -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
这里有一些要注意的地方,
<mirror>在这一段代码里面,id是我们在一.4步骤里面创建的Group ID, name是Group Name, mirrorOf里面填*表示为所有仓库做镜像,你也可以只填一个在url里面,注意到最后的public-repositories与id的值是一致的.不能乱填.
<id>public-repositories</id>
<mirrorOf>*</mirrorOf>
<name>Public Repositories</name>
<url>http://192.168.110.44:8081/nexus/content/groups/public-repositories/</url>
</mirror>
<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版本的.