zoukankan      html  css  js  c++  java
  • 微服务编译、启动jar命令指定配置文件

    在部署项目的时候会有dev、test、uat、prod等环境配置文件

    有两种方法去指定配置文件:

    1、在启动服务的时候指定;

    2、编译打包的时候指定,如果此时已经指定则启动的时候就不用再指定了。

    1、启动服务时指定配置文件

    nohup java -Xms512m -Xmx8g -Xmn512m -Xss512k -server -XX:+HeapDumpOnOutOfMemoryError -jar smp-bill-controller-1.0-SNAPSHOT.jar --spring.profiles.active=test > /dev/null 2>&1 &

    nohup java -Xms512m -Xmx8g -Xmn512m -Xss512k -server -XX:+HeapDumpOnOutOfMemoryError -jar smp-bill-controller-1.0-SNAPSHOT.jar --spring.profiles.active=test > /dev/null 2>&1 &

     蓝色表示指定配置文件为测试环境,文件路径如下图:

    2、编译打包时指定配置文件

    可以在后方加上 -P uat,表示使用uat环境的配置文件

    mvn clean package -DskipTests=true -P uat

    前提是需要在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>cn.net.yto.retail.service.product</groupId>
        <artifactId>e-product</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>e-product-controller</module>
            <module>e-product-service</module>
            <module>e-product-mapper</module>
        </modules>
    
        <properties>
            <cs.dir>${basedir}/..</cs.dir>
            <java.version>1.8</java.version>
            <yto-framework-dependencies.version>1.0.1</yto-framework-dependencies.version>
            <components.version>1.0.0</components.version>
            <mybatis-generator-core.version>1.3.5</mybatis-generator-core.version>
            <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
            <maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
            <maven-source-plugin.version>2.4</maven-source-plugin.version>
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>net.ytoframework</groupId>
                    <artifactId>yto-framework-dependencies</artifactId>
                    <version>${yto-framework-dependencies.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-core</artifactId>
                    <version>${mybatis-generator-core.version}</version>
                </dependency>
                <dependency>
                    <groupId>cn.net.yto.retail.components</groupId>
                    <artifactId>e-components-utils</artifactId>
                    <version>${components.version}</version>
                </dependency>
                <dependency>
                    <groupId>cn.net.yto.retail.components</groupId>
                    <artifactId>e-components-dto</artifactId>
                    <version>${components.version}</version>
                </dependency>
                <dependency>
                    <groupId>cn.net.yto.retail.components</groupId>
                    <artifactId>e-components-cache</artifactId>
                    <version>${components.version}</version>
                </dependency>
                <dependency>
                    <groupId>cn.net.yto.retail.components</groupId>
                    <artifactId>e-components-security</artifactId>
                    <version>${components.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <build>
            <resources>
                <resource>
                    <directory>${project.basedir}/src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>${maven-compiler-plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>${maven-checkstyle-plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${maven-source-plugin.version}</version>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <configuration>
                        <attach>true</attach>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <profiles>
            <profile>
                <id>dev</id>
                <properties>
                    <envddd>dev</envddd>
                </properties>
            </profile>
            <profile>
                <id>test</id>
                <properties>
                    <envddd>test</envddd>
                </properties>
            </profile>
            <profile>
                <id>uat</id>
                <properties>
                    <envddd>uat</envddd>
                </properties>
            </profile>
            <profile>
                <id>prod</id>
                <properties>
                    <envddd>prod</envddd>
                </properties>
            </profile>
        </profiles>
    </project>
  • 相关阅读:
    在有多个input的表单当中按回车按钮,如何不自动提交表单,而触发某个按钮的事件
    login.jsp
    json数据源
    translation.js
    cookie.js
    i18next.min.js
    struts2拦截器实现原理
    proxy-target-class="true" 与proxy-target-class="false"的区别(声明事务的时候)
    NavLink
    【转载】target='_blank' 安全漏洞示例
  • 原文地址:https://www.cnblogs.com/gcgc/p/10563016.html
Copyright © 2011-2022 走看看