Unable to build adapters using profiles and properties in Maven

孤街醉人 提交于 2019-12-04 15:21:12

In MobileFirst Foundation 8.0 you can use either the MobileFirst CLI or Maven to update the server with different "profiles". See here: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/javascript-adapters/#pull-and-push-configurations

CLI:

  • mfpdev adapter pull
  • mfpdev adapter push

Maven:

  • mvn adapter:configpull -DmfpfConfigFile=config.json
  • mvn adapter:configpush -DmfpfConfigFile=config.json

After you deploy your adapter for the first time, use the mfpdev adapter pull command. Because you did not alter any value via the MobileFirst Operations Console just yet, this will create an empty config.json file at the root of the adapter directory (i.e. JavaScriptHTTP\config.json):

{ }

You can now edit this config file for a specific "profile", and then duplicate it for each of the other "profiles".

To edit it more easily, it is better to first edit the various properties in the console first and then pull them, in order to created a populated config.json file. For example, after changing the domain, port and protocol values, saving the changes and running the pull command, the config.json file will be populated with the following:

{"connectivity":{"http":{"protocol":{"value":"http"},"port":{"value":4431},"domain":{"value":"ibmcloud.com"}}}}

You can beautify it to:

{
    "connectivity": {
        "http": {
            "protocol": {
                "value": "http"
            },
            "port": {
                "value": 4431
            },
            "domain": {
                "value": "ibmcloud.com"
            }
        }
    }
}

Now duplicate this file for each "profile" and customize the values.
You can then push it back to the server.

  1. Deploy the adapter as-is (doesn't matter what are its default properties in the adapter.xml since these will be overwritten based on the config file you'll push).

  2. Push the specific config.json file: mfpdev adapter push.

Learn more here: https://mobilefirstplatform.ibmcloud.com/blog/2017/01/03/tools-for-devops-flows-with-mobilefirst-foundation/

If you need to store different files, such as: dev.json, qa.json, uat.json and prod.json, you can still do this, however instead of the CLI - Use Maven:

mvn adapter:configpush -DmfpfConfigFile=config.json

Replace "config.json" with the name of the appropriate .json file.

Alternatively, continue using your current implementation and by using mvn compile. You can also use Maven command to build and deploy the adapter: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/creating-adapters/

As a workaround you can set the path to your generated adapter.xml in pom.xml.

```
<build>
<resources>
  <resource>
    <directory>src/main/adapter-resources</directory>
    <filtering>true</filtering>
    <targetPath>${adapterResourcePath}</targetPath>
  </resource>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>
<plugins>
  <plugin>
    <groupId>com.ibm.mfp</groupId>
    <artifactId>adapter-maven-plugin</artifactId>
    <version>${version.mffadapter.plugin}</version>
    <extensions>true</extensions>
    <executions>
      <execution>
        <goals>
          <goal>build</goal>
        </goals>
        <configuration combine.self="override">
          <adapterResourcesDir implementation="java.io.File">${adapterResourcePath}
          </adapterResourcesDir>
        </configuration>
      </execution>
    </executions>
  </plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!