Maven发布war到私服

Maven发布war到私服

pom配置

  <distributionManagement>
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://172.16.20.103:8081/repository/maven-snapshots/</url>
    </snapshotRepository>

    <repository>
      <id>releases</id>
      <url>http://172.16.20.103:8081/repository/maven-releases/ </url>
    </repository>
  </distributionManagement>

如果是snapshots的,pom的版本号后面的snapshot必须是大写 SNAPSHOT,如下

 <groupId>com.fsl</groupId>
    <artifactId>lcp.hotfix</artifactId>
    <version>2.0-SNAPSHOT</version>
    <packaging>war</packaging>

settings文件配置

	<server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server> 

    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

snapshots的版本为不稳定版本,可在不更改版本号的前提下,多次发布,私库会自动添加日期区分,同时使用方可配置为自动更新最新的snapshots(为了安全,maven组件默认关闭的,下面的配置二选一便可以)

项目pom.xml如下配置

<repositories>
    <repository>
        <id>nexus</id>
        <name>ex</name>
        <url>http://172.16.20.103:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

maven的settings.xml中配置

<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>central</id>
                <name>Nexus</name>
                <url>http://172.16.20.103:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <name>Nexus</name>
                <url>http://172.16.20.103:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>
<activeProfiles>
  <activeProfile>nexus</activeProfile>
</activeProfiles>

activeProfile一定要加,不然配置不生效。结构很简单,以profile的形式引入,pluginRepository节点可以不用引入,但是snapshots enabled必须设置为true。

参考 https://www.cnblogs.com/EasonJim/p/8318219.html

 

===================源码打包===================

使用maven-source-plugin插件将项目源码打包并发布到仓库中,在pom.xml配置文件中添加如下的配置代码:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>
    <configuration>
        <attach>true</attach>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>



在intellij idea中执行maven install即可

执行 mvn install,maven会自动将source install到repository 。 
执行 mvn deploy,maven会自动将source deploy到remote-repository 。 
执行 mvn source:jar,单独打包源码。

 

============================war-作为overlays使用=======================

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <attachClasses>true</attachClasses><!-- 把class打包jar作为附件 -->
                </configuration>
            </plugin>

引用war并合并overlays

  
        <dependency>
            <groupId>com.fsl</groupId>
            <artifactId>lcp.hotfix</artifactId>
            <classifier>classes</classifier>
            <scope>provided</scope>
            <version>2.0-SNAPSHOT</version>
        </dependency> 

        <dependency>
            <groupId>com.fsl</groupId>
            <artifactId>lcp.wrapper</artifactId>
            <type>war</type>
            <version>2.0-RELEASE</version>
        </dependency>










  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <attachClasses>true</attachClasses>
                    <overlays>
                        <!-- 合并 war包 -->
                        <overlay>
                            <groupId>com.fsl</groupId>
                            <artifactId>lcp.extension</artifactId>
                        </overlay>

                      <overlay>
                            <groupId>com.fsl</groupId>
                            <artifactId>lcp.hotfix</artifactId>
                        </overlay> 

                        <overlay>
                            <groupId>com.fsl</groupId>
                            <artifactId>lcp.wrapper</artifactId>
                            <excludes>
                                <exclude>WEB-INF/lib/hap*</exclude>
                            </excludes>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值