无法使用 Maven 中的配置文件和属性构建适配器

2024-04-05

我已经使用创建了一个http适配器mfpdev adapter create但我发现 adatper.xml 配置文件包含服务器连接配置,我想相应地更改为 dev、test、produciton 环境。

所以我尝试通过更改 pom.xml 来使用 Maven 资源过滤器,如下所示

pom.xml

<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>com.my.adapter</groupId>
<artifactId>MYAPIAdapter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>adapter</packaging>
<name>MYAPIAdapter</name>

<properties>
    <!-- Use UTF-8 as the encoding of the adapter -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- MobileFirst adapter deployment properties -->
    <mfpfUrl>http://localhost:9080/mfpadmin</mfpfUrl>
    <mfpfUser>admin</mfpfUser>
    <mfpfPassword>admin</mfpfPassword>
    <mfpfRuntime>mfp</mfpfRuntime>
</properties>

<dependencies>
    <dependency>
        <groupId>com.ibm.mfp</groupId>
        <artifactId>adapter-maven-api</artifactId>
        <scope>provided</scope>
        <version>[8.0.0,9.0.0)</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.mfp</groupId>
        <artifactId>mfp-security-checks-base</artifactId>
        <version>[8.0.0,9.0.0)</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.ibm.mfp</groupId>
            <artifactId>adapter-maven-plugin</artifactId>
            <extensions>true</extensions>
        </plugin>
    </plugins>
    <filters>
        <filter>profiles/${build.profile.id}/config.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/adapter-resources</directory>
            <filtering>true</filtering>
        </resource>
</resources>
</build>

<profiles>
    <profile>
        <id>pc</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.profile.id>pc</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>sit</id>
        <properties>
            <build.profile.id>sit</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>uat</id>
        <properties>
            <build.profile.id>uat</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <build.profile.id>prod</build.profile.id>
        </properties>
    </profile>
</profiles>

适配器.xml

<mfp:adapter name="MYAPIAdapter"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:mfp="http://www.ibm.com/mfp/integration"
         xmlns:http="http://www.ibm.com/mfp/integration/http">

<displayName>MYAPIAdapter</displayName>
<description>MYAPIAdapter</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol> ${connect.protocol}</protocol>
        <domain> ${connect.domain}</domain>
        <port> ${connect.port}</port>
        <connectionTimeoutInMilliseconds> ${connect.timeout.ms}</connectionTimeoutInMilliseconds>
        <socketTimeoutInMilliseconds> ${connect.sockettimeout.ms}</socketTimeoutInMilliseconds>
        <maxConcurrentConnectionsPerNode> ${max.concurrentconnections}</maxConcurrentConnectionsPerNode>
    </connectionPolicy>
</connectivity>

<procedure name="getFeed"/>
<procedure name="unprotected" secured="false"/>

当我跑步时mvn install,我遇到了以下错误,似乎 mfp maven 插件验证了适配器 xml 文件。我运行没有问题mvn compile并且适配器 xml 值已成功替换为属性文件中的值。在构建 mfp 适配器时是否可以从属性文件中指定配置?

ERROR] Failed to execute goal com.ibm.mfp:adapter-maven-plugin:8.0.2016082422:build (default-build) on project MYAPIAdapter: Adapter xml file schema validation encountered errors: [cvc-datatype-valid.1.2.1: '${connect.port}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.port}' of element 'port' is not valid., cvc-datatype-valid.1.2.1: '${connect.timeout.ms}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.timeout.ms}' of element 'connectionTimeoutInMilliseconds' is not valid., cvc-datatype-valid.1.2.1: '${connect.sockettimeout.ms}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${connect.sockettimeout.ms}' of element 'socketTimeoutInMilliseconds' is not valid., cvc-datatype-valid.1.2.1: '${max.concurrentconnections}' is not a valid value for 'integer'., cvc-type.3.1.3: The value '${max.concurrentconnections}' of element 'maxConcurrentConnectionsPerNode' is not valid.] -> [Help 1] [ERROR] 

在 MobileFirst Foundation 8.0 中,您可以使用 MobileFirst CLI 或 Maven 来更新具有不同“配置文件”的服务器。看这里:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/javascript-adapters/#pull-and-push-configurations 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

首次部署适配器后,请使用mfpdev adapter pull命令。因为你没有改变任何值通过 MobileFirst Operations Console到目前为止,这将创建一个empty适配器目录根目录下的 config.json 文件(即 JavaScriptHTTP\config.json):

{ }

您现在可以为特定“配置文件”编辑此配置文件,然后为其他每个“配置文件”复制它。

为了更容易地编辑它,最好先在控制台中编辑各种属性,然后拉取它们,以便创建一个填充的 config.json 文件。例如,更改后domain, port and protocol值,保存更改并运行pull命令,config.json 文件将填充以下内容:

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

您可以将其美化为:

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

现在为每个“配置文件”复制此文件并自定义值。
那么你可以push它返回到服务器。

  1. 按原样部署适配器(adapter.xml 中的默认属性是什么并不重要,因为这些属性将根据您要推送的配置文件被覆盖)。

  2. 推送具体的config.json文件:mfpdev adapter push.

在这里了解更多:https://mobilefirstplatform.ibmcloud.com/blog/2017/01/03/tools-for-devops-flows-with-mobilefirst-foundation/ https://mobilefirstplatform.ibmcloud.com/blog/2017/01/03/tools-for-devops-flows-with-mobilefirst-foundation/

如果您需要存储不同的文件,例如:dev.json、qa.json、uat.json 和 prod.json,您仍然可以执行此操作,但不是使用 CLI - 使用 Maven:

mvn adapter:configpush -DmfpfConfigFile=config.json

将“config.json”替换为适当的 .json 文件的名称。

或者,继续使用当前的实现并使用mvn compile。您还可以使用 Maven 命令来构建和部署适配器:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/creating-adapters/ https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/creating-adapters/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 Maven 中的配置文件和属性构建适配器 的相关文章

随机推荐

  • CIDetector跟踪ID从不存在

    我正在 OSX Mavericks 上编写一些人脸检测代码 并尝试利用 CIDetector 提供的跨多个静止图像功能的新 截至 10 8 人脸跟踪 我的基本面部检测工作正常 如下所示 void captureOutput AVCaptur
  • 如何在面板数据中为不同年份创建单独的直方图?

    我有一个数据框报纸 年 其中包含每年一组报纸的发行量 CIRC 我想看看这些数字的分布如何随时间变化 所以我想为这些不同的年份创建多个单独的直方图 我已经尝试过以下方法 ggplot newspaper yearly aes x CIRC
  • YouTube URL 方案 tvOS

    我正在尝试使用 URL 方案或 YouTube com 域从我的应用程序打开 YouTube 的应用程序 从而直接在 iOS 设备上打开 YouTube 的应用程序 这是我尝试过的代码 UIApplication sharedApplica
  • 如何访问shinyapps.io上应用程序的R+Shiny代码?

    我发现了一个设计非常好的闪亮应用程序闪亮应用程序io https wuli shinyapps io QuoiR 网站 但我不知道如何访问它R代码或说出github其代码目录 我发现如果我们能够访问它的代码 这非常有启发性 无论如何 在最坏
  • SQLAlchemy 布尔值与 BOOLEAN 的比较

    我理解了BOOLEAN覆盖 visit name class BOOLEAN Boolean visit name BOOLEAN 控制调度程序选择的访问者方法 def compiler dispatch self visitor kw v
  • Java 编写单元测试,用于当用户在控制台中键入 quit 时退出程序

    我发现很难为这种方法编写单元测试 当用户键入退出命令时 它基本上会退出程序 系统退出类 public class SystemExit public void exit int status System exit status 我的静态方
  • 如何制作圆形按钮?

    我想制作一个圆形按钮 但我不知道该怎么做 我可以制作带有圆角的按钮 但是我怎样才能制作圆形 这是不一样的 请问一下 安卓上可以吗 谢谢 创建一个名为的 xml 文件roundedbutton xml在可绘制文件夹中
  • 为什么 cv2.rectangle 有时返回 np.ndarray,而有时返回 cv2.UMat

    我目前正在研究一些图像的可视化 并发现 opencv 的 cv2 rectangle 的奇怪行为 当输入图像是 np ndarray 时 例如 arr cv2 rectangle 返回一个 np ndarray 并且 arr 是用矩形绘制的
  • 如何禁用默认消息:“您的请求已成功处理”?

    当在我的 portlet 中执行添加 更新操作时 如何为我的插件 portlet 禁用此默认消息 您的请求已成功处理 另外我想为我的自定义配置页面禁用此功能 configuration jsp 这是当我们单击每个 Portlet 右上角出现
  • 这个“你好世界!”是怎么做到的?程序工作?

    int main void return yes no main printf hello world n 0 outputs hello world 但它实际上是如何工作的呢 确实有两件事 函数指针不像其他指针那样取消引用 main ma
  • Powershell - 排除 Get-ChildItem 中的文件夹

    如何排除文件夹 现在我对文件夹名称进行硬编码 但我希望它更加灵活 foreach file in Get ChildItem fileDirectory Exclude folderA folderb 如何排除文件夹 如果您指的是所有文件夹
  • libpcap 在它们下面使用原始套接字吗?

    我对原始套接字和 libcap 的使用感到有点困惑 任何人都可以简单地指出使用两者的优点 我读了几个链接 但是 它让我感到困惑 libpcap 在不同的操作系统上使用不同的机制 在 Linux 上 它使用 PF PACKET 原始套接字或熟
  • 如何根据 Mongodb 中的键删除重复项?

    我在 MongoDB 中有一个集合 其中大约有 约 300 万条记录 我的样本记录看起来像 id ObjectId 50731xxxxxxxxxxxxxxxxxxxx source references id ObjectId 5045xx
  • 为什么“OR 运算”或 OR 条件不可控制?

    在文献中 我读到在 WHERE 子句中使用 OR 条件或运算符会生成一个语句non sargable 我不确定为什么或如何这是真的 任何帮助 将不胜感激 权威优化书籍作者给出了答案SQL Server 查询性能调优 https rads s
  • 创建动画按钮

    我有按钮可以在单击时创建动画吗 使用 Photoshop 我创建了两个图像 启用和禁用 在Windows窗体中插入图片框并单击事件 单击图像从启用变为禁用 但是可以有动画吗 像这样 看来您提到了 WinForms 所以我将解决这个问题 是的
  • 测试元素焦点

    我如何检查这个TextInput组件是否受到关注 我知道该怎么做在网上 https spectrum chat testing library general how to test element is focused 7Eabdca78
  • PHP 循环内循环,选择了选项吗?

    使用 PHP 我在循环中回显表行 如下所示
  • 如何使用 $dateFromString 转换数组中的日期?

    我正在尝试使用 dateFromString 将数组中的时间戳转换为日期 我试图从中转换日期的示例文档 id ObjectId 5cbc5efc8af5053fd8bdca31 ticker ticker currency currency
  • Java分割字符串的表现

    这是我的应用程序中的当前代码 String ids str split 在分析应用程序时 字符串分割花费了不可忽视的时间 另外 split方法采用正则表达式 这在这里是多余的 我可以使用什么替代方法来优化字符串分割 是StringUtils
  • 无法使用 Maven 中的配置文件和属性构建适配器

    我已经使用创建了一个http适配器mfpdev adapter create但我发现 adatper xml 配置文件包含服务器连接配置 我想相应地更改为 dev test produciton 环境 所以我尝试通过更改 pom xml 来