简体   繁体   中英

Setting Microprofile active profile using mp.config.profile not working in Liberty

Im currently trying to run a microprofile open liberty project as a jar.

java -jar myapp.jar -Dmp.config.profile=test

The app runs but is not picking the configuration values from microprofile-config-test.properties instead is using values from microprofile-config.properties

Thank you in advance

Enabling MicroProfile Config 2.0 Feature

First, you enable in your server.xml via:

    <featureManager>
        <feature>mpConfig-2.0</feature>  
        <!-- 
            Or enable all MicroProfile 4.0 features via:
            <feature>microProfile-4.0</feature>   
          -->
    </featureManager>

Installing GA version of Open Liberty

Default version

By default, liberty-maven-plugin will install the latest version of Open Liberty.

Installing a specific GA version

You can install a specific version of Open Liberty (eg version 21.0.0.3 which contains the GA support for MicroProfile 4.0 features such as MicroProfile Config 2.0) via liberty-maven-plugin config:

    <plugin>
        <groupId>io.openliberty.tools</groupId>
        <artifactId>liberty-maven-plugin</artifactId>
        <version>3.3.4</version>
        <configuration>
            <assemblyArtifact>
                <groupId>io.openliberty</groupId>
                <artifactId>openliberty-runtime</artifactId>
                <version>21.0.0.3</version>
            </assemblyArtifact>
        </configuration>
    </plugin>

Installing a beta version of Open Liberty with liberty-maven-plugin

UPDATE: (I originally posted this answer when the MicroProfile Config 2.0 feature was still in beta, but for reference I'll move this to a new section below.)

Here is how to install a specific version of the Open Liberty runtime beta, using the liberty-maven-plugin:

    <plugin>
        <groupId>io.openliberty.tools</groupId>
        <artifactId>liberty-maven-plugin</artifactId>
        <version>3.3.4</version>
        <configuration>
            <assemblyArtifact>
                <groupId>io.openliberty.beta</groupId>
                <artifactId>openliberty-runtime</artifactId>
                <version>21.0.0.3-beta</version>
                <type>zip</type>
            </assemblyArtifact>
        </configuration>
    </plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM