mvn 打包war

打包war

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test.manager</groupId>
  <artifactId>test.manager</artifactId>
  <version>0.0.2-SNAPSHOT</version>  
  <packaging>war</packaging>
  <name>test.manager</name>
  <description/>
  <properties>
    <webVersion>2.5</webVersion>
	<servlet.version>3.1.0</servlet.version>
   <jsp.version>2.2</jsp.version>
   <jstl.version>1.2.5</jstl.version>
   
    <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
	<docker.repostory>10.0.2.4:5000</docker.repostory>
	<docker.dockerhost>http://10.0.2.4:5000</docker.dockerhost>
	<docker.registry.name>hnzyst</docker.registry.name>
	<docker.artifactId>ddc.manager</docker.artifactId>
	<!-- 指定docker image 的版本号 -->
	<docker.version>1.0.0</docker.version>
	<docker.active>test</docker.active>
  </properties>
  
  <dependencies>
 <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>${servlet.version}</version>
   <scope>provided</scope>
</dependency>
  
<dependency>
   <groupId>javax.servlet.jsp</groupId>
   <artifactId>jsp-api</artifactId>
   <version>${jsp.version}</version>
   <scope>provided</scope>
</dependency>

</dependencies>
  <build>
  <sourceDirectory>${basedir}/src</sourceDirectory>  
  <outputDirectory>${basedir}/WebRoot/WEB-INF/classes</outputDirectory>  
	<resources> 
            <!--指定xml文件位置-->
            <resource>
                <directory>${basedir}/src</directory>
                <includes>
                    <include> *.xml</include>
					<include> *.properties</include>
					<include> com/aj/**/config/*.xml</include> 
					<include> com/aj/**/**/config/*.xml</include> 
                </includes>
                <filtering>true</filtering>
            </resource>
			
			<resource>
                        <directory>${basedir}/docker/${docker.active}</directory>
                        <includes>
                            <include>remote.xml</include>
							<include>processors.xml</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
     </resources>
 
    <plugins>
	
	<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>
    <configuration>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>  
	 </plugin>
	 
	 <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding> 
           <compilerArguments>            
            <extdirs>WebRoot/WEB-INF/lib</extdirs> 
          </compilerArguments> 
			
        </configuration>
      </plugin>
	   

      
       <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration> 
                <failOnMissingWebXml>false</failOnMissingWebXml> 
                <webResources>
                        <resource>
                            <!--配置本地jar包在项目中的存放路径-->
                            <directory>${basedir}/WebRoot/</directory>
                            <!--配置打包时jar包的存放路径-->
                            <targetPath>/</targetPath>
                            <includes>
                                <include>**/*.*</include>
                            </includes>
                        </resource> 
                 </webResources>
            </configuration> 
      </plugin> 
	  
      <!-- 打包Docker -->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.13</version>
            <executions>
                <execution>
                    <id>build-image</id>
                    <phase>package</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
                <execution>
                    <id>tag-image</id>
                    <phase>package</phase>
                    <goals>
                        <goal>tag</goal>
                    </goals>
                     <configuration>
                        <image> ${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}:${docker.version}</image> 
                        <newName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}:${docker.version}</newName> 
                    </configuration>
                </execution>
                 <execution>
                    <id>push-image</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>push</goal>
                    </goals>
                    <configuration>
                        <imageName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}:${docker.version}</imageName>
                    </configuration>
                </execution>   
            </executions>
            <configuration>
                <serverId>docker-local</serverId>
                <registryUrl>${docker.dockerhost}</registryUrl>
                <pushImage>true</pushImage>
                <dockerDirectory>${project.basedir}/docker/build</dockerDirectory>
                <imageName>${docker.repostory}/${docker.registry.name}/${docker.active}/${docker.artifactId}</imageName>
                <imageTags>
                    <imageTag>${docker.version}</imageTag>
                </imageTags>
                <resources>
                  <resource>
                    <targetPath>/</targetPath>
                    <directory>${basedir}/target/</directory>
                    <include>test.manager.war</include>
                  </resource>
                </resources>
            </configuration>
        </plugin>

    </plugins>
     <finalName>test.manager</finalName>
  </build>
</project>

运行打包

mvn clean install -Ddocker.version=1.0.0. -Ddocker.active=test

启动命名

#!/bin/bash
docker rm -f test.manager
docker run -d -p 8090:8080 --network mynet   --link fjdcgl.server --name test.manager 10.0.2.4:5000/hnzyst/test/test.manager
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值