Java—profile与logback配置

非spring相关的项目下使用logback,有时也需要根据profile进行不同的配置。

1、父pom的配置

//可执行jar包的插件配置
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>

2、子module的配置





//根据不同的环境配置profile定义在打包的过程中,需要包含哪些资源文件,配置不同的logback-xx配置文件
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <dockerHost>http://192.168.58.18:2375</dockerHost>
            <registry>harbor.aolingo.com</registry>
            <username>aolingo</username>
            <password>你的密码</password>
        </properties>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>logback-dev.xml</include>
                        <include>application.yaml</include>
                    </includes>
                </resource>
            </resources>
        </build>
    </profile>
<profiles>

//指定主类,配合父pom中的maven-shade-plugin插件完成可独立运行的jar包
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>
                            com.aolingo.starchat.gateway.GatewayEntry
                        </mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

3、打包命令

mvn clean package -Ptest -pl starchat-gateway