* 熟悉创建mvn archetype:generate -D….创建maven骨架*
pom.xml
|-src
|—main
|—-java
|——package
|—-resource
|—test
|—-java
|——package
|—-resource
|-target 通过compile或者带有compile目标任务的命令 就会编译源文件到target—>classes中(如果真的目标任务,就去看一下maven的生命周期管理,这个有时间再写)
|—classes
大概说一下,重点关注compile
maven生命周期分三套
- clean
- compile
- site
当执行mvn:clean 的时候的过程是
1. pre-clean 执行一些需要再clean之前完成的工作
2. clean 移除所有上次构建生成的文件
3. post-clean 执行clean之后的工作
当执行mvn:compile的过程(plugins插件中的目标)是
validate
generate-sources
process-sources
generate-resource
process-resource 复制并处理资源文件,至目标目录,准备打包
compile 编译源代码 (如果mvn:compile相当于就执行到这里终止)
process-classes
generate-test-source
process-test-source
generate-test-resource
process-test-resource 复制并处理资源文件至目标测试目录
test-compile 编译测试源代码 (如果mvn:test就执行到这里终止)
process-test-classes
test 使用合适的单元框架运行测试,这些测试不会打包和部署。
prepare-package
package 接收编译好的源代码,打包成可发布的文件,如jar (如果mvn:package就执行到这里终止)
pre-integration-test
integration-test
post-integration-test
verify
install 将包安装到本地仓库,供其他项目依赖 (如果mvn:install就执行到这里终止)
deploy 将最终到包复制到远程仓库,让其他开发人员于项目共享 (如果mvn:deploy就执行到这里终止)
当执行mvn:site时会生成一个站点,具体没研究
***eclipse集成maven插件
解决一些配置小问题(更新包结构,让eclipse认识maven项目为java项目,更新pom.xml中maven compile错误,更新idk警告)*
测试依赖传递
- eg: service模块需要依赖dao模块,那么dao模块首先需要mvn install到repository,service依赖的时候才能有效
* eg:排除xxxxxx,dependency节点增加exclusions*
<exclusions>
<exclusion>
<groupId>xxxxxxgroupId>
<artifactId>xxxxxartifactId>
exclusion>
exclusions>
<modelVersion>4.0.0modelVersion>
<groupId>org.jm.testgroupId>
<artifactId>jm-parentartifactId>
<version>0.0.1-SNAPSHOTversion>
<packaging>pompackaging>
<url>http://maven.apache.orgurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>
<modules>
<module>../项目1module>
<module>../项目2module>
<module>../项目3module>
modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.10version>
<scope>testscope>
<exclusions>
<exclusion>
<groupId>xxxxxxgroupId>
<artifactId>xxxxxartifactId>
exclusion>
exclusions>
dependency>
<dependency>……dependency>
<dependency>……dependency>
<dependency>……dependency>
dependencies>
dependencyManagement>
其他继承的项目pom.xml如下
<modelVersion>4.0.0modelVersion>
<groupId>org.jm.testgroupId>
<artifactId>mvntestartifactId>
<version>0.0.1-SNAPSHOTversion>
<relativePath>../jm-parent/pom.xmlrelativePath>
<packaging>jarpackaging>
<name>mvntestname>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
dependency>
dependencies>
eg:a.b.c-XXX
* a : 大修改,重构或者产品重定位灯
* b : 分支
* c : 分支中的小迭代更新
* XXX : 里程碑(SNAPSHOT开发中,alpha内测,beta公测,Release(RC)发行版 , General Available(GA)正常稳定版)
例如:
0.0.1-SNAPSHOT 意思就是开始开发的第一个版本
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-source-pluginartifactId>
<version>2.4version>
<executions>
<execution>
<phase>compilephase>
<goals>
<goal>jar<goal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<version>3.0version>
<configuration>
<source>1.6source>
<target>1.6target>
configuration>
plugin>
plugins>
pluginManagement>
build>
在被依赖的modules中加入
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
plugin>
plugins>
build>
新建maven项目–选择artifactId选择maven-archetype-webapp
pom.xml中的packaging中就是
cargo插件可以发布多种web服务器应用
推荐使用jetty插件
mvn:clean compile jettyrun
nexus 是通过jetty容器运行的,所以提前需要安装jre运行环境并配置好了环境变量
目前免费版是2.x,所以下载个免费版
https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.13.0-01-bundle.tar.gz
[root@localhost ~]# tar -zxvf nexus-2.13.0-01-bundle.tar.gz
[root@localhost download]# ll
total 70780
drwxr-xr-x. 8 1001 1001 4096 Apr 12 16:11 nexus-2.13.0-01 #nexus 服务
-rw-r--r--. 1 root root 72466664 Jun 23 08:28 nexus-2.13.0-01-bundle.tar.gz
drwxr-xr-x. 3 1001 1001 4096 Apr 12 16:21 sonatype-work #私有库目录
[root@localhost conf]# pwd
/root/download/nexus-2.13.0-01/conf
[root@localhost conf]# vim nexus.properties
# Jetty section
application-port=8081 #默认访问端口,可以修改为自己需要的端口,并加入到iptables链
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF
[root@localhost conf]# vi /root/download/nexus-2.13.0-01/bin/nexus
#RUN_AS_USER=
改为:
RUN_AS_USER=root
# vi /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT 保存后重启防火墙
# service iptables restart
[root@localhost conf]# /root/download/nexus-2.13.0-01/bin/nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
网上资料很多,参考几篇就搞定了。
http://www.cnblogs.com/luotaoyeah/p/3791966.html
http://blog.csdn.net/ichsonx/article/details/14642897
切换中央仓库为阿里云仓库,修复索引
加入central到public仓库地址,这样才能正常下载到依赖
首先需要配置是的maven的setting.xml文件,我直接全部放上来,具体看注释
<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>/Users/jm/Documents/work/mrepositorylocalRepository>
<pluginGroups/>
<proxies/>
<servers>
<server>
<id>nexus-rsid>
<username>deploymentusername>
<password>xiaoshoujia123password>
server>
<server>
<id>nexus-snapshotsid>
<username>deploymentusername>
<password>xiaoshoujia123password>
server>
servers>
<mirrors>
<mirror>
<id>nexus-publicid>
<mirrorOf>centralmirrorOf>
<name>central repositoryname>
<url>http://192.168.199.146:8081/nexus/content/groups/public/url>
mirror>
mirrors>
<profiles>
<profile>
<id>nexusid>
<repositories>
<repository>
<id>nexus-rsid>
<name>Nexus Release Snapshot Repositoryname>
<url>http://192.168.199.146:8081/nexus/content/repositories/releasesurl>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
<repository>
<id>nexus-snapshotsid>
<url>http://192.168.199.146:8081/nexus/content/repositories/snapshotsurl>
<releases><enabled>trueenabled>releases>
<snapshots><enabled>trueenabled>snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-rsid>
<name>Nexus Release Snapshot Repositoryname>
<url>http://192.168.199.146:8081/nexus/content/repositories/releasesurl>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
<pluginRepository>
<id>nexus-snapshotsid>
<url>http://192.168.199.146:8081/nexus/content/repositories/snapshotsurl>
<releases><enabled>trueenabled>releases>
<snapshots><enabled>trueenabled>snapshots>
pluginRepository>
pluginRepositories>
profile>
<profile>
<id>sonarid>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
<properties>
<sonar.jdbc.url>
jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.url>
<sonar.jdbc.username>rootsonar.jdbc.username>
<sonar.jdbc.password>rootsonar.jdbc.password>
<sonar.host.url>
http://127.0.0.1:9000/sonar
sonar.host.url>
properties>
profile>
profiles>
<activeProfiles>
<activeProfile>nexusactiveProfile>
activeProfiles>
settings>
根节点project中增加
<distributionManagement>
<repository>
<id>nexus-rsid>
<name>Nexus Release Repositoryname>
<url>http://192.168.199.146:8081/nexus/content/repositories/releases/url>
repository>
<snapshotRepository>
<id>nexus-snapshotsid>
<name>Nexus Snapshot Repositoryname>
<url>http://192.168.199.146:8081/nexus/content/repositories/snapshots/url>
snapshotRepository>
distributionManagement>
到此,nexus就可以和项目结合使用了。