Maven build标签与springboot项目打包引入lib目录下jar包

举报
DevFeng 发表于 2021/11/12 18:19:23 2021/11/12
【摘要】 前言 <build >的作用与本地lib的构件。分类在Maven的pom.xml文件中,存在如下两种<build>:(1)全局配置(project build)         针对整个项目的所有情况都有效(2)配置(profile build)           针对不同的profile配置<project xmlns="http://maven.apache.org/POM/4.0.0...

前言

 <build >的作用与本地lib的构件。

分类

在Maven的pom.xml文件中,存在如下两种<build>:

(1)全局配置(project build)

         针对整个项目的所有情况都有效

(2)配置(profile build)

           针对不同的profile配置

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">  
  ...  
  <!-- "Project Build" contains elements of the BaseBuild set and the Build set-->  
  <build>...</build>  
   
  <profiles>  
    <profile>  
      <!-- "Profile Build" contains elements of the BaseBuild set only -->  
      <build>...</build>  
    </profile>  
  </profiles>  
</project>
build>被称为Project Build,即是<project>的直接子元素
profile-build>被称为Profile Build,即是<profile>的直接子元素。

配置及参数说明

<build>  
  <defaultGoal>install</defaultGoal>  
  <directory>${basedir}/target</directory>  
  <finalName>${artifactId}-${version}</finalName>   
<filters>  
<filter>filters/filter1.properties</filter>  
</filters>   ...
</build>
1)defaultGoal

     执行build任务时,如果没有指定目标,将使用的默认值。

     如上配置:在命令行中执行mvn,则相当于执行mvn install

2)directory
      build目标文件的存放目录,默认在${basedir}/target目录

3)finalName

       build目标文件的名称,默认情况为${artifactId}-${version}

4)filter

         定义*.properties文件,包含一个properties列表,该列表会应用到支持filter的resources中。

         也就是说,定义在filter的文件中的name=value键值对,会在build时代替${name}值应用到resources中。

          maven的默认filter文件夹为${basedir}/src/main/filters

 Resources配置

<build>  
        ...  
       <resources>  
          <resource>  
             <targetPath>META-INF/plexus</targetPath>  
             <filtering>true</filtering>  
            <directory>${basedir}/src/main/plexus</directory>  
            <includes>  
                <include>configuration.xml</include>  
            </includes>  
            <excludes>  
                <exclude>**/*.properties</exclude>  
            </excludes>  
         </resource>  
    </resources>  
    <testResources>  
        ...  
    </testResources>  
    ...  
</build>
              1)resources

                    一个resources元素的列表。每一个都描述与项目关联的文件是什么和在哪里

              2)targetPath

                    指定build后的resource存放的文件夹,默认是basedir。

                    通常被打包在jar中的resources的目标路径是META-INF

             3)filtering

                    true/false,表示为这个resource,filter是否激活
             4)directory

                    定义resource文件所在的文件夹,默认为${basedir}/src/main/resources

             5)includes

                    指定哪些文件将被匹配,以*作为通配符

             6)excludes

                   指定哪些文件将被忽略

             7)testResources

                   定义和resource类似,只不过在test时使用

springboot项目打包引入lib目录下jar包

pom文件中引入jar

		<!-- 引入本地jar -->
		<dependency>
			<groupId>com.topsoft</groupId>
			<artifactId>cms-pak</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/main/resources/lib/com-xxx-demo.jar</systemPath>
		</dependency>

打war包

定义打包类型

	<groupId>com.zzy</groupId>
	<artifactId>com-xxx-demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

定义war包插件 

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<webResources>
						<resource>
						    <!-- 原路径 -->
							<directory>src/main/resources/lib</directory>
							<targetPath>WEB-INF/lib/</targetPath>
							<includes>
								<include>**/*.jar</include>
							</includes>
						</resource>
					</webResources>
				</configuration>
			</plugin>

打可执行jar包

定义打包类型

	<groupId>com.zzy</groupId>
	<artifactId>cms-pak-demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

定义jar包插件 

			<!-- 打jar包 -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<mainClass>com.*.MainApplication</mainClass>
					<includeSystemScope>true</includeSystemScope>
				</configuration>
			</plugin>

 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200