Maven

maven 私服;
Maven项目对象模型(POM)

下载 apache-maven-3.3.9-bin.tar.gz 

1、环境变量设置:

java 环境变量:
/etc/profile export JAVA_HOME=/usr/local/java export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$java_home/lib/dt.jar:$JAVA_HOME/lib/tools.jar maven 环境变量: /etc/profile export MAVEN_HOME=/vdb/maven export MAVEN=$MAVEN_HOME/bin export PATH=$MAVEN:$PATH

2、版本验证;
# mvn -version

3、Nexus搭建maven私有库自动打包
nexus-2.14.2-01-bundle.tar.gz

Nexus 配置:

[root@test]# cat conf/nexus.properties |grep -v ^# |grep -v ^$
application
-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus nexus-webapp-context-path=/nexus nexus-work=${bundleBasedir}/../sonatype-work/nexus runtime=${bundleBasedir}/nexus/WEB-INF storage.diskCache.bufferSize=4096

启动:

进入bin目录运行nexus;
cd nexus/bin
启动
./nexus start
关闭
./nexus stop

URL 访问:

http://localhost:8081/nexus/index.html 
默认账户:admin 
默认密码:Admin123

界面设置:

1、将所有type为proxy的configuration配置选项中DownloadRemoteIndex置为True,然后点击Save保存;
其中3rd party选项中可以上传第三方jar包一些maven下载不下来的,公共仓库上找不到的,就可以在3rd party中的Artifacts upload选项卡中上传jar包;

2、新建组 将右边的Available Repositories全部拖到左边点击Save保存 ;
3、最后右键项目->Run As->Run Configurations双击左边选项卡的 Maven Build 新建一个;

仓库地址/名称
3rd party    第三方的包
http://172.16.2.15:8081/nexus/content/repositories/thirdparty/

Central    中心仓
http://172.16.2.15:8081/nexus/content/repositories/central/

Releases 内部包发布仓
http://172.16.2.15:8081/nexus/content/repositories/releases/
POM 引入相关发布仓
······
<repositories>
<repository>
<id>dc-releases</id>
<name>dc releases</name>
<url>http://172.16.2.15:8081/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>dc-central</id>
<name>dc central</name>
<url>http://172.16.2.15:8081/nexus/content/repositories/central/</url>
</repository>
<repository>
<id>dc-thirdparty</id>
<name>dc thirdparty</name>
<url>http://172.16.2.15:8081/nexus/content/repositories/thirdparty/</url>
</repository>
</repositories>
······

引入依赖jar包
······
<dependency>
<groupId>com.xiaojing.datacenter</groupId>
<artifactId>xiaojing-dc-utils</artifactId>
<version>1.0.0</version>
</dependency>
····
<dependency>
<groupId>com.xiaojing.datacenter</groupId>
<artifactId>xiaojing-dc-elasticsearch</artifactId>
<version>1.0.0</version>
</dependency>
·····

需要注意的是,当pom.xml中同时配置了releases仓库和snapshots仓库时;
pom.xml文件开头的版本配置<version>1.0.0-SNAPSHOT</version>为build到snapshots库,
而<version>1.0.0</version>**不带-SNAPSHOT的会build到releases库,
如果只配置了releases库而版本号写的是带-SNAPSHOT的,build到最后一步会报400错误。

 MVN 常用参数了解

mvn 的几个参数的解释,有兴趣可以参考下:
mvn -DskipTests clean package

打包:mvn package
编译:mvn compile
编译测试程序:mvn test-compile
清空:mvn clean
运行测试:mvn test
生成站点目录: mvn site
生成站点目录并发布:mvn site-deploy
安装当前工程的输出文件到本地仓库: mvn install

结尾:这样大致就完成了jenkins的打包构建,但是默认构建完成,war包是不会再这个工程中出现的,需要开启这个功能,配置如下:(默认是没有的)添加内容如下:(**/target/*.war)

Jenkins 编译其他语言:

.net 项目:
MSBuild Plugin

maven 项目 :
maven Integration plugin

Deploy to Container Plugin 插件(这个是支持将代码部署到tomcat容器的)
原文地址:https://www.cnblogs.com/sharesdk/p/9205628.html