bat脚本,批量打包maven项目

6 篇文章 0 订阅
  • bat脚本目录
    在这里插入图片描述
  • cmd执行命令
    在这里插入图片描述
    在这里插入图片描述
  • 脚本内容(只执行的maven的编译脚本,其中-Ptest(中的test对应主pom.xml里activeByDefault=true对应的id值))

mvn clean install -Dmaven.test.skip=true -Dmaven.compile.fork=true -Ptest
mvn clean install 删除重新编译
-Dmaven.test.skip=true 不执行测试用例,也不编译测试用例类(-DskipTests不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下)
-Dmaven.compile.fork=true 用以指明多线程进行编译
-Ptest P代表(Profiles配置文件),在<profiles>指定的<id>中,可以通过-P进行传递或者赋值。
相关详情连接

@echo off
echo 1、执行打包脚本至UAT环境或release环境
mvn clean install -Dmaven.test.skip=true -Dmaven.compile.fork=true -Ptest

set CurrentDir=%cd%
set TargetFolder=target\

if not exist %CurrentDir%%TargetFolder% (
	md %cd%\target
)

echo 2、复制打包后的文件至target文件夹

copy %currentDir%\打的jar包相对于项目的位置\target\trte-be-serce-0.0.1-SNAPSHOT.zip %TargetFolder%
copy %currentDir%\打的jar包相对于项目的位置\target\trte-or-serce-0.0.1-SNAPSHOT.zip %TargetFolder%
copy %currentDir%\打的war包相对于项目的位置\target\trte-web.war %TargetFolder%

pause
  • 打包成功后,注释maven编译,执行bat后面的复制包脚本
@echo off
echo 1、执行打包脚本至UAT环境或release环境
-- mvn clean install -Dmaven.test.skip=true -Dmaven.compile.fork=true -Ptest

set CurrentDir=%cd%
set TargetFolder=target\

if not exist %CurrentDir%%TargetFolder% (
	md %cd%\target
)

echo 2、复制打包后的文件至target文件夹

copy %currentDir%\打的jar包相对于项目的位置\target\trte-be-serce-0.0.1-SNAPSHOT.zip %TargetFolder%
copy %currentDir%\打的jar包相对于项目的位置\target\trte-or-serce-0.0.1-SNAPSHOT.zip %TargetFolder%
copy %currentDir%\打的war包相对于项目的位置\target\trte-web.war %TargetFolder%

pause
  • 打包成功
    在这里插入图片描述
  • 主pom.xml
    在这里插入图片描述
    主pom.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.itek.atp</groupId>
    <artifactId>slate</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>translate</name>
	
	<profiles>
		<profile>
			<!-- 本地开发环境 -->
			<id>dev</id>
			<properties>
				<profiles.active>dev</profiles.active>
			</properties>
		</profile>
		
		<profile>
			<!-- 发布环境 -->
			<id>release</id>
			<properties>
				<profiles.active>release</profiles.active>
			</properties>
		</profile>
		<profile>
			<!-- 测试环境 -->
			<id>test</id>
			<properties>
				<profiles.active>test</profiles.active>
			</properties>
			<activation>
				<!-- 设置默认激活这个配置 -->
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>
		<profile>
			<!-- 演示环境 -->
			<id>uat</id>
			<properties>
				<profiles.active>uat</profiles.active>
			</properties>
		</profile>
	</profiles>

    <modules>
	<!-- module 顺序的改变会影响打包 -->
		<module>trte-be</module>
		<module>trte-or</module>
		<module>trte-web </module>
	</modules>
	
	
	<pluginRepositories>
		<pluginRepository>
			<id>central</id>
			<name>central</name>
			<url>http://10.40.204.239:8081/nexus/content/groups/public</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

	<repositories>
		<repository>
			<id>public</id>
			<name>Public Repositories</name>
			<url>http://10.40.204.239:8081/nexus/content/groups/public/</url>
			<layout>default</layout>
		</repository>
	</repositories>

	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>Release</name>
			<url>http://10.40.204.239:8081/nexus/content/repositories/releases/</url>
			<uniqueVersion>true</uniqueVersion>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>Snapshot</name>
			<url>http://10.40.204.239:8081/nexus/content/repositories/snapshots/</url>
			<uniqueVersion>true</uniqueVersion>
		</snapshotRepository>
	</distributionManagement>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
		<java-version>1.7</java-version>
		<org.springframework.version>4.1.2.RELEASE</org.springframework.version>
		<org.slf4j-version>1.7.9</org.slf4j-version>
		<logback.version>1.1.3</logback.version>
		<dubbo.version>2.8.4</dubbo.version>
		<resteasy-version>3.0.14.Final</resteasy-version>
		<sitemesh.version>2.4.2</sitemesh.version>
		
		<maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
    </properties>

</project>

子pom内容:

<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>
	<parent>
		<artifactId>iflyframework</artifactId>
		<groupId>com.iflytek</groupId>
		<version>${project.version}</version>
	</parent>
	<artifactId>iflyframework-api</artifactId>
	<description>dubbo service</description>

	<!-- dubbo服务端相关jar包依赖 -->
	<dependencies>
		<!-- dubbo dependency -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.zookeeper</groupId>
			<artifactId>zookeeper</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
		</dependency>
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.cache</groupId>
			<artifactId>cache-api</artifactId>
		</dependency>
	</dependencies>
	
	<build>
        <resources>
            <resource>
				<targetPath>${project.build.directory}/classes</targetPath>
                <directory>profiles/${profile.active}</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*.properties</include>
                </includes>
            </resource>
			<resource>
				<targetPath>${project.build.directory}/classes</targetPath>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/**/*.xml</include>
					<include>*.xml</include>
				</includes>
			</resource>
        </resources>
        <plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<classDirectory>target/classes</classDirectory>
					<archive>
						<addMavenDescriptor>false</addMavenDescriptor>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<mainClass>com.alibaba.dubbo.container.Main</mainClass>
							<useUniqueVersions>false</useUniqueVersions>
						</manifest>
						<manifestEntries>
							<Class-Path>.</Class-Path>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<type>jar</type>
							<includeTypes>jar</includeTypes>
							<useUniqueVersions>false</useUniqueVersions>
							<outputDirectory>
								${project.build.directory}/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
            <plugin>
				<groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
					<appendAssemblyId>false</appendAssemblyId>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>${project.build.sourceVersion}</source>
					<target>${project.build.targetVersion}</target>
				</configuration>
			</plugin>
        </plugins>
    </build>
</project>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值