为什么80%的码农都做不了架构师?>>>   

阅读此文的前提,对Maven 有一定了解,熟悉pom文件基础

1:Nexus 建立私服 去下载nexus的war包格式的,最新版本的要使用高版本的web容器; 如:,下载后直接放到tomcat下 ,启动运行

 登陆进去可以看到默认有多个仓库了

手动建立仓库 ,仓库分类有1:宿主仓库 2:代理仓库 3:仓库组 关于建立私服,也很简单,不会的 推荐区看《Maven实战》

这里是我创建的 自己的仓库,也包含有默认仓库

2:pom.xml配置

<!-- lang: java -->
<!-- 为此项目配置仓库(repositories)和插件仓库(pluginRepositories),这里配置Nexus私服仓库,配置在pom中,表示只在当前项目中有效 。在实际应用中,我们往往通过配置setting.xml使本机所有Maven项目都是用指定的私服 -->
<repositories><repository><id>dy_nexus_group</id><name>dy_nexus_group</name><url>http://localhost:8080/nexus/content/groups/dy_nexus_group</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository>
</repositories>
<pluginRepositories><pluginRepository><id>dy_nexus_group</id><name>dy_nexus_group</name><url>http://localhost:8080/nexus/content/groups/dy_nexus_group</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository>
</pluginRepositories>
    <!-- 发布构件 -->
<!-- Nexus的仓库对于匿名用户是只读的,为了能够部署构件,还需要在setting.xml配置认证信息 -->
<distributionManagement><repository><id>dy_nexus_hosted_release</id><name>dy_nexus_hosted_release</name><url>http://localhost:8080/nexus/content/repositories/dy_nexus_hosted_release</url></repository><snapshotRepository><id>dy_nexus_hosted_snapshot</id><name>dy_nexus_hosted_snapshot</name><url>http://localhost:8080/nexus/content/repositories/dy_nexus_hosted_snapshot</url></snapshotRepository>
</distributionManagement><!-- Maven属性 :包括内置属性,pom属性,setting属性,自定义属性,java系统属性,环境变量属性,参见p.280-->
<properties><springframework.version>3.2.8</springframework.version>
</properties><!-- 资源过滤 -->
<profiles><!-- 针对开发环境的数据库设置 (开发环境)clean compile install -Pdy.dev --><!-- spring配置中通过${db.driver}就可以拿到此处的配置值了 --><!-- Profile激活有多种方式详见:p.285 --><profile><id>dy.dev</id><properties><myprop>dy.dev</myprop><!-- <db.driver>com.mysql.jdbc.Driver</db.driver><db.url>jdbc:mysql://127.0.0.3306/dev</db.url><db.username>pom.dev</db.username><db.password>pom.dev</db.password><db.maxIdle>11</db.maxIdle><db.maxActive>111</db.maxActive> --></properties><!-- 默认自动激活 --><activation><activeByDefault>true</activeByDefault></activation></profile><!-- 针对开发环境的数据库设置 (开发环境)clean compile install -Pdy.test --><profile><id>dy.test</id><properties><myprop>dy.test</myprop></properties></profile><!-- 针对开发环境的数据库设置 (开发环境)clean compile install -Pdy.prod --><profile><id>dy.prod</id><properties><myprop>dy.prod</myprop></properties></profile>
</profiles>

配置依赖: <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency>

    <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${springframework.version}.RELEASE</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><scope>provided</scope></dependency>
</dependencies>

构建项目:

 <!-- 打包和发布的最终名字-->
<finalName>hello-world</finalName> <!-- 配置过滤自定义的资源文件 -->
<filters><filter>${project.basedir}/${myprop}.properties</filter>
</filters> <!-- 为主资源目录开启过滤-->
<resources><resource><directory>${project.basedir}/src/main/resources</directory><filtering>true</filtering></resource>
</resources>
<testResources><testResource><directory>${project.basedir}/src/test/resources</directory><filtering>true</filtering></testResource>
</testResources>
<!-- Cargo是一组帮助用户操作web容器的工具。其提供两种本地部署的方式:standalone模式和existing模式。 --><!-- standalone模式中:Cargo会从web容器的安装目录复制一份配置到用户指定的目录,然后在此基础上部署应用。每次重新构建的时候,这个目录被清空,所有配置重新清空。--><!-- existing模式中:用户需要指定现有web容器的配置目录,然后Cargo会直接使用这些配置并将应用部署到其  对应的目录。运行命令:cargo:run(需要配置pluginGroups 详见setting.xml)--><!-- 更多设置可参见官网: http://cargo.codehaus.org -->
<plugin><groupId>org.codehaus.cargo</groupId><artifactId>cargo-maven2-plugin</artifactId><version>1.2.4</version><configuration><container><containerId>tomcat7x</containerId><home>F:/apache-maven-3.0.5-test/apache-tomcat-7.0.33</home></container><!-- <configuration><type>standalone</type><home>${project.build.directory}/tomcat7x</home><properties><cargo.servlet.port>8081</cargo.servlet.port></properties></configuration> --><configuration><type>existing</type><home>F:/apache-maven-3.0.5-test/apache-tomcat-7.0.33</home></configuration></configuration>
<!-- lang: java -->

<!-- 部署至远程服务器,前提是拥有该容器的相应管理员权限,配置如下: -->

           <configuration><container><containerId>tomcat7x</containerId><type>remote</type></container><configuration><!--远程正在运行的服务器 --><type>runtime</type><properties><cargo.hostname>192.168.168.50</cargo.hostname><cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding><cargo.remote.username>dengyang</cargo.remote.username><cargo.remote.password>dengyang</cargo.remote.password><cargo.tomcat.manager.url>http://192.168.168.50:8080/manager</cargo.tomcat.manager.url></properties></configuration></configuration></plugin>

...... tomcat7.x 的tomcat-user.xml 配置管理员账户(tomcat6配置还不太一样) 如下:

<!-- lang: js -->
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<!-- lang: xml -->
<user username="dengyang" password="dengyang" roles="admin,admin-gui,admin-script,manager,manager-       script,manager-gui"/>

3:setting.xml配置

        <!-- lang: java -->
<localRepository>F:\JAVA_TOOLS\TOOLS\Maven\local_maven_repository</localRepository>本地仓库地址
<servers><!-- Nexus的仓库对于匿名用户是只读的,为了能够部署构件,还需要在setting.xml配置认证信息, <server>中的id 和<repository>中的id完全一致 -->
<server><id>dy_nexus_hosted_release</id><username>admin</username><password>admin123</password>
</server>
<server><id>dy_nexus_hosted_snapshot</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> <!-- lang: java -->以下配置说明:本机所有maven项目私服配置仓库(repositories)和插件仓库(pluginRepositories),这样配置除了会去私服nexus下载构件外,还会不时地访问中央仓库, 但我们希望的是所有构件和依赖下载的请求都仅仅通过Nexus,以全面发挥私服的作用。 这时候就需要配置Maven镜像了。
<profile>
<id>my_nexus</id>
<repositories><repository><id>dy_nexus_group</id><name>dy_nexus_group</name><url>http://localhost:8080/nexus/content/groups/dy_nexus_group</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots><layout>default</layout></repository>
</repositories>
<pluginRepositories><pluginRepository><id>dy_nexus_group</id><name>dy_nexus_group</name><url>http://localhost:8080/nexus/content/groups/dy_nexus_group</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository>
</pluginRepositories>
</profile> -->去mirrors下,增加配置,并修改此处配置:
<!--如果仓库X可以提供仓库Y存储的所有内容,那么就可以认为X是Y的一个镜像。 dy_nexus_group仓库组中增加central代理仓库以及其他你自己的仓库--><mirrors>
<mirror><id>my_nexus</id><mirrorOf>*</mirrorOf><name>maven mirror for my nexus</name><url>http://localhost:8080/nexus/content/groups/dy_nexus_group</url>
</mirror>
</mirrors><!-- 修改以上profile配置如下:修改后配置,即使用maven镜像配置,这里同时配置了插件仓库,用不到也可以不配置; 仓库和插件仓库id都为central意味覆盖了超级pom的中央仓库的配置 --><profile>
<id>my_nexus</id>
<repositories><repository><id>central</id><name>central</name><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots><layout>default</layout></repository>
</repositories>
<pluginRepositories><pluginRepository><id>central</id><url>http://central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository>
</pluginRepositories>
</profile><!-- 使用activeProfiles 将my_nexus私服激活 , activeProfile 对应profile 中的id,使用maven镜像的时候 此处对应的是mirror中的id--><activeProfiles>
<activeProfile>my_nexus</activeProfile>
</activeProfiles><!-- lang: xml -->使用cargo命令配置: <pluginGroups>
<pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>此文主要用于个人总结,可能有很多人看不明白,可以联系我dyyweb@163.com,也可以问度娘!

转载于:https://my.oschina.net/dyyweb/blog/227189

maven小节,Nexus私服,构件打包发布,动态资源过滤,自动部署到本地或远程服务器...相关推荐

  1. SpringBoot + Vue打包部署到本地和远程服务器

    最近碰到有人问如何将SpringBoot和Vue进行打包部署到Tomcat服务器,由于Vue接触不是很久所以我自己也感兴趣是如何打包部署到本地或者远程服务器上(云端).恰好手上也有一个案例需要部署到远 ...

  2. 配置Maven从Nexus下载构件

    配置Maven从Nexus下载构件  当需要为项目添加Nexus私服上的public仓库时,配置如下: <project>     ...     <repositories> ...

  3. Maven配置nexus私服地址

    一般java开发都会用到nexus私服,这里记录一下maven配置nexus私服地址的步骤 配置全局和本用户下两个setting.xml 镜像地址 一般maven本地用户的配置文件在我的文档目录下.m ...

  4. Maven搭建Nexus私服

    私服的介绍 1 什么是私服 私服是一种特殊的远程仓库,它是架设在局域网的仓库服务,私服代理广域网上的远程仓库,供局域网使用. 在企业开发中,私服的建设是有必要的,其好处如下: 1.1 节省资金.外网带 ...

  5. jenkins搭建教程及使用ant对非maven的javaweb项目进行打包发布到远程tomcat服务器

    一.环境准备 (1)CentOS 7 (2)关闭防火墙.关闭selinux 二.软件安装 使用jenkins前需要安装jdk和maven,安装过程相信大家都了解,就不在这里赘述了. jenkins安装 ...

  6. Maven整合Nexus私服

    nexus 上传jar包到私服 从私服下载jar包 方式1 :配置maven的setting.xml文件 方式2 :配置项目里的pom.xml文件 nexus nexus的下载与安装和启动 上传jar ...

  7. Maven之nexus(私服)

    1Nexus介绍 Nexus是一个强大的Maven仓库管理器, 它极大地简化了自己内部仓库的维护和外部仓库的访问. 利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Art ...

  8. 【坑2】maven通过nexus私服服务器下载jar包提示无权限Authentication failed for http://localhost:8081/repository/maven-pub

    Authentication failed for http://localhost:8081/repository/maven-public/log4j/log4j/1.2.16/log4j-1.2 ...

  9. nexus私服知识概括

    nexus私服知识概括 nexus私服简介 Nexus仓库分类 nexus注意点 nexus总结 nexus私服简介 私服: 私服也是远程仓库中的一种,我们为什么需要私服呢? 如果我们一个团队中有几百 ...

最新文章

  1. asp.net前台与后台访问
  2. 【蓝桥杯Java_C组·从零开始卷】第三节、while循环do while循环for循环(超重点)break终止循环continue结束本次循环
  3. 日志转化成json格式
  4. centos下mysql 命令,CentOS下mysql 常用命令
  5. 接口implements
  6. C# 程序启动其他进程程序
  7. STM32 HAL库学习系列第3篇 常使用的几种延时方式
  8. mysql5.095下载_战舰世界095版本
  9. 嵌入式开发Verilog教程(一)——数字信号处理、计算、程序、 算法和硬线逻辑的基本概念
  10. 海康威视设备发现sdp原理
  11. 如何将Python程序打包成linux可执行文件
  12. NA Express
  13. 一篇文章说尽,中国互联网的30年(完结篇)
  14. python 计算置信区间,Python求解正态分布置信区间
  15. 可获取公网IP的网址
  16. 【前端之旅】Webpack模块打包工具
  17. 我想找份好工作之“避免入黑坑公司宝典”
  18. 嗨!Java Coder,考考你们看代码的眼力
  19. 七个人生工具:SWOT、PDCA、6W2H、SMART、WBS、时间管理、二八原则
  20. 添加163镜像为linux yum源,163镜像yum源配置----centos7

热门文章

  1. blockingqueue java_记录 Java 的 BlockingQueue 中的一些坑
  2. Halcon知识 : 乘法图像融合
  3. redux react ajax,使用react-redux触发事件操作
  4. mysql制作html静态网页6_将数据库中的所有内容生成html静态页面的代码
  5. kdj指标主要看哪个值_什么是KDJ?KDJ指标如何使用
  6. 怎么做才能让浏览器看不到token_卫生间回填及防水怎么做才能后患无忧
  7. java 垃圾回收 指针_Java 和 C++ 垃圾回收之间的差别
  8. mfc vs2013 项目怎么更改类名_VS2010 更改MFC标题及标题栏图标和exe图标
  9. MySQL防止重复插入唯一限制的数据 4种方法
  10. MySQL的limit用法和分页查询的性能分析及优化