1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>book</groupId>
    <artifactId>book</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>book</name>
 
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
 
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
 
        <package.environment>local</package.environment>
    </properties>
 
    <dependencies>
 
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
 
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
 
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
 
    </dependencies>
 
 
    <profiles>
        <profile>
            <id>local</id>
            <properties>
                <package.environment>local</package.environment>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <package.environment>product</package.environment>
            </properties>
        </profile>
    </profiles>
 
    <build>
        <finalName>book</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>local/*</exclude>
                    <exclude>product/*</exclude>
                    <exclude>public/*</exclude>
                </excludes>
            </resource>
        </resources>
 
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <warName>book</warName>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/${package.environment}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/resources/public</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                        <!--<resource>-->
                            <!--<directory>${project.build.directory}/classes</directory>-->
                            <!--<includes>-->
                                <!--<include>**/*.properties</include>-->
                                <!--<include>**/*.xml</include>-->
                            <!--</includes>-->
                        <!--</resource>-->
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

其中, 我们注意的地方: 我解释一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<profiles>
        <profile>
            <id>local</id>
            <properties>
                <package.environment>local</package.environment>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <package.environment>product</package.environment>
            </properties>
        </profile>
    </profiles>

这里就是不同的resources文件夹, 我这里只区分本地 产品; 设置为true的就是默认被激活的. 所以后面打包默认就是本地;

1
2
3
4
5
6
7
8
9
10
11
<resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>local/*</exclude>
                    <exclude>product/*</exclude>
                    <exclude>public/*</exclude>
                </excludes>
            </resource>
        </resources>

这里就是我的资源文件, public里面存放我的公用的, 比如Spring的配置文件, 就是本地与产品都一样的;local 与 product一看就知道了;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <warName>book</warName>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/${package.environment}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/resources/public</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                        <!--<resource>-->
                            <!--<directory>${project.build.directory}/classes</directory>-->
                            <!--<includes>-->
                                <!--<include>**/*.properties</include>-->
                                <!--<include>**/*.xml</include>-->
                            <!--</includes>-->
                        <!--</resource>-->
                    </webResources>
                </configuration>
            </plugin>

这里就是war的插件了,

1
${package.environment}

就是动态指定文件夹了.

1
<filtering>true</filtering>

这里一定需要设置为true才行.

然后就差不多了. 最后执行 mvn clean ; mvn compile; mvn package; 这里是Maven的生命周期, 其他介绍的文章太多了, 我就不再具体讲. 如果说我要打product的war包;

mvn clean ; mvn compile; mvn -Pproduct package;

那就激活了product 的资源文件;

就这样子, 很简单吧~

Maven_根据不同个环境打包, 获取不同的配置文件等等的更多相关文章

  1. Maven根据不同个环境打包, 获取不同的配置文件等等

    http://www.cnblogs.com/tartis/p/5391079.html <project xmlns="http://maven.apache.org/POM/4.0 ...

  2. 用maven按环境打包SpringBoot的不同配置文件

    利用maven按环境打包SpringBoot的不同配置文件 application-dev.properties对应开发环境 application-test.properties对应测试环境 app ...

  3. maven 使用-P指定环境打包,linux移动配置文件失败,windows成功!

    问题描述:    windows机器使用-P指定环境打包,最后组装文件组装成功,配置文件成功移动,linux下却只移动了jar包. windows:                  linux:   ...

  4. 前端自动分环境打包(vue和ant design)

    现实中的问题:有时候版本上线的时候,打包时忘记切换环境,将测试包推上正式服务器,那你就会被批了. 期望:在写打包的命令行的时候就觉得自己在打包正式版本,避免推包时候的,不确信自己的包是否正确. 既然有 ...

  5. php7+apache2.4 (Windows7下),成功启动。(楼主另外提供了1个php7集成环境打包: http://pan.baidu.com/s/1qXwjpF2 ,如果你只是想了解一下,放在d盘根目录。)

    php7正式版已经发布,性能是php5.4的2倍.博主入手php7 新鲜了一把,下面是解决问题之后成功启动php7的记录. ( 电脑必须win7 sp1, .netframework4 ) Windo ...

  6. maven为不同环境打包(hibernate)-超越昨天的自己系列(6)

    超越昨天的自己系列(6) 使用ibatis开发中,耗在dao层的开发时间,调试时间,差错时间,以及适应修改需求的时间太长,导致项目看起来就添删改查,却特别费力.   在项目性能要求不高的情况下,开始寻 ...

  7. Maven插件之portable-config-maven-plugin(不同环境打包)

    在大型的项目组中,分不同的开发环境,测试环境,生产环境(说白了就是配置文件不同,或者数据源,或者服务器,或者数据库等);问题来了,如何使用Maven针对不同的环境来打包呢? Maven提供了Profi ...

  8. 规范开发目录 及 webpack多环境打包文件配置

    规范开发目录 普通项目 开发目录: ├── project-name ├── README.md ├── .gitignore ├── assets ├── ├── js ├── ├── css ├─ ...

  9. Vue项目分环境打包的实现步骤

    转:https://blog.csdn.net/xinzi11243094/article/details/80521878 方法一:亲测真的有效 在项目开发中,我们的项目一般分为开发版.测试版.Pr ...

随机推荐

  1. HDU5792 World is Exploding(树状数组)

    一共6种情况,a < b且Aa < Ab, c < d 且Ac > Ad,这两种情况数量相乘,再减去a = c, a = d, b = c, b = d这四种情况,使用树状数组 ...

  2. wp8 入门到精通 Animation 背景加字体颜色从下向上变化颜色效果

    <phone:PhoneApplicationPage.Resources> <Style x:Key="ButtonStyle1" TargetType=&qu ...

  3. codeforces724-A. Checking the Calendar 日期题

    首先有这样一个显然的事实,那就是每个月的第一天可以是星期x,x可以取遍1~7 因为日期一直在往后退,总有一年能轮到分割线那天,因为本来其实压根就没有月份的划分,月份划分是人为的 而且我们也不知道开始的 ...

  4. 解决Kali Linux没有声音

    解决Kali Linux没有声音   Kali Linux系统默认状态下,root用户是无法使用声卡的,也就没有声音.启用的方法如下: (1)在终端执行命令:systemctl --user enab ...

  5. 07 JavaWeb

    软件开发的两种架构:c/s和b/s          * C/S     client/server     客户端/服务器     例子:QQ     快播     暴风影音...          ...

  6. TestNg依赖配置基础用法(单一方法依赖)------TestNg依赖详解(一)

    TestNg依赖测试之简单方法依赖,通过dependsOnMethods属性来配置依赖方法 原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong J ...

  7. hdu 5459 Jesus Is Here (费波纳茨递推)

    Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission ...

  8. java 常见下载合集

    J2SE SDK (JDK): Windows: http://download.oracle.com/auth/otn-pub/java/jdk/6u25-b06/jdk-6u25-windows- ...

  9. NoSQL-Redis【2】-实现分布式Session

    经过一周紧张的开发和调试,终于把Redis实现的分布式Session发布到了生产环境.我在本地测试了100万的数据,Redis的速度确实让我满意,期待在线上有更好的表现. 一.配置windows-se ...

  10. Codeforces 677E Vanya and Balloons(DP + 一些技巧)

    题目大概说给一张地图,地图每个格子都有0到9中的某一个数字.现在要在一个格子放炸弹,炸弹爆炸后水柱有两种扩展方式,一种是上.下.左.右,另一种是左上.右下.右上.左下,且四个方向的长度都一样.问放哪个 ...