zoukankan      html  css  js  c++  java
  • 配置开发环境测试环境线上生产环境

        1.正确打包

            项目有三种环境:

            1.本地开发环境(local)

            2.开发测试环境(dev)

            3.线上生产环境(product)

            不同的环境有不同的配置,比如数据库连接什么的....maven打包时默认去resources文件夹下打包这些配置文件,放在WEB-INF/classes下,然后再打成war包,就能用了...现在通过修改pom.xml文件,增加三种配置,让maven打包时选择打包不同文件夹下的配置文件到WEB-INF/classes下,这样就省事儿了....

            如图所示,resources下dev,local,product三个文件夹,分别对应三种环境。

    下面是pom.xml主要修改:

    <!--配置参数-->
    <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>
        <profile>
            <id>dev</id>
            <properties>
                <package.environment>dev</package.environment>
            </properties>
        </profile>
    </profiles> 
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>local/*</exclude>
                    <exclude>product/*</exclude>
                    <exclude>dev/*</exclude>
                </excludes>
            </resource>
        </resources>
      <!-- war打包插件, 设定war包名称不带版本号 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceExcludes>*/lib/jsp-api-2.2.jar</warSourceExcludes>
                <warName>gcTaobao</warName>
                <webResources>
                    <!--动态指定文件-->
                    <resource>
                        <directory>src/main/resources/${package.environment}</directory>
                        <targetPath>WEB-INF/classes</targetPath>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin></build>

    1. <profiles>标签里的三个<profile>是分别指local , dev ,product 三个参数。

    2.<resources>标签里<excludes>确认在打包时不打包对应三个文件夹以及里面的文件。

    3.org.apache.maven.plugins插件<webResources>动态指定参数${package.environment}对应文件夹下的文件到WEB-INF/classes下。

    到此就配置好了:

    下面是maven命令

    然后就可以用mvn -P local package 或者mvn -P install 就可以打包成功了。

    2.jetty本地debug配置

        按照上面的配置,打出的war可以正确使用,但是在使用maven jetty插件时,jetty自动加载的时target/classes中的文件。你可以发现使用上面的配置编译出来的target/classes的文件里没有对应的jdbc等文件。这里的解决方案是更改jetty加载classes路径来解决。

        具体配置:

    <artifactId>${artifactId}</artifactId>
    <version>${version}</version>
    <properties>
        <artifactId>AAA</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </properties>
    <build>
        <!-- 配置加入jetty服务器,开发时我们一般使用jetty服务器 -->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
                <!--jetty:run指定加载classes路径-->
                <classesDirectory>target/${artifactId}-${version}/WEB-INF/classes</classesDirectory>
                <!-- 设置扫描target/classes内部文件变化时间间隔 -->
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webApp>
                    <contextPath>/</contextPath>
                </webApp>
                <stopKey/>
                <stopPort/>
            </configuration>
        </plugin>
    </build>

        maven打包时生成 一个 artifactId-version的文件夹,里面有对应的WEB-INF/classes文件,<classesDirectory>标签指定jetty加载里面的classes下文件,里面有也有对应的配置文件,这样就可以正常本地启动了。

    3.idea中的操作

        install直接选择具体参数,然后点击install就可以了,多选参数时,会出现覆盖的情况。

        如图

  • 相关阅读:
    PostgreSQL的MVCC(4)--Snapshots
    PostgreSQL的MVCC(3)--Row Versions
    PostgreSQL的MVCC(2)--Forks, files, pages
    asynchelper在一个同步方法(非async)方法中等待async方法
    restTemplate工具类【我】
    String字符串类型转数字进行计算及其他校验
    高并发系统设计(七):【Mysql数据库的优化】主从读写分离、分库分表
    高并发系统设计(六):如何减少频繁创建数据库连接的性能损耗?
    高并发系统设计(五):【系统设计目标③】如何让系统易于扩展?
    高并发系统设计(四):【系统设计目标②】系统怎样做到高可用?
  • 原文地址:https://www.cnblogs.com/nunuAction/p/6901000.html
Copyright © 2011-2022 走看看