maven不同配置文件打包

1、不同配置文件对应不同环境,例:dev对应测试坏境,properties对应开发坏境

2、修改配置文件pom.xml
添加如下代码:
<profiles>
<profile>
<id>properties</id>
<properties>
<package.environment>properties</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
3、添加打包代码:主要代码为下划线处
<build>
        <finalName>feidieshuo-workbench</finalName>
         <plugins> 
       <plugin>    
         <groupId>org.apache.maven.plugins</groupId>    
       <artifactId>maven-compiler-plugin</artifactId>   
         <version>3.1</version>      
         <configuration>    
    <source>1.7</source>    
    <target>1.7</target> 
    <encoding>UTF-8</encoding>
       </configuration> 
       </plugin> 
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
                <webResources>
                    <resource>
                        <!-- this is relative to the pom.xml directory -->
                        <directory>src/main/resources/${package.environment}</directory>
                        <targetPath>WEB-INF/classes</targetPath>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
     </plugins>
    </build>
4、打包命令:
用maven -v检查maven是否安装
cmd指定到对应pom.xml位置下执行下面语句
mvn clean install -Dmaven.文件名.skip=true -P=文件名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven POM (Project Object Model) 文件是 Maven 项目的核心配置文件,其中包含了项目中所有的依赖、插件、构建配置等信息。在 Maven 打包过程中,POM 文件的正确配置非常重要。以下是一个基本的 Maven POM 文件配置示例: ```xml <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.example</groupId> <artifactId>my-app</artifactId> <version>1.0-SNAPSHOT</version> <!-- 依赖声明 --> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <!-- 插件声明 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.example.App</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project> ``` 在上述 POM 文件中,`<groupId>`、`<artifactId>` 和 `<version>` 标签定义了项目的基本信息。`<dependencies>` 标签用于声明项目所依赖的其他库,`<build>` 标签下的 `<plugins>` 标签用于声明项目构建时所需要的插件。 在打包过程中,可以使用以下命令: ``` mvn package ``` 该命令会在当前项目根目录下生成一个名为 `my-app-1.0-SNAPSHOT.jar` 的可执行 JAR 文件,其中包含了项目的所有依赖和代码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值