带有外部库的IBM MobileFirst Adapters

时间:2017-06-07 13:09:38

标签: ibm-mobilefirst mobilefirst-adapters mobilefirst-cli

在IBM MobileFirst 8.0中使用带有Java适配器的外部库是否有任何限制?

当我添加guava时,我的代码没有错误(mfpdev适配器构建成功),但在部署到我的服务器时,它会响应错误:

\n

但是当我在pom(mvn依赖项)中删除guava时,我能够部署适配器。我可以看到的问题也发生在其他一些库中。有没有选择使用这样的库?

mfpdev -v:8.0.0-2017012016

编辑:我最终通过在pom文件中设置guava的范围来解决问题:

$n

1 个答案:

答案 0 :(得分:0)

我在MFP 8.0环境中试过这个,但没有看到问题。

mfpdev -v
8.0.0-2017012016

0. Create  a sample Java adapter "mfpdev adapter create" 
1. Added dependency with guava 21 in pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>

2. added a simple guava package and used it.

import com.google.common.base.Optional;

@GET

        @Produces(MediaType.TEXT_PLAIN)
        public String getResourceData() {
                // log message to server log
                logger.info("Logging info message...");
                Integer invalidInput = new Integer(20);
      Optional<Integer> a =  Optional.of(Input);
      Optional<Integer> b =  Optional.of(new Integer(10));
      logger.info("Logging my message with guava");
      );
        return "Hello from guava resource "+sum(a,b) ;
       }

4. build, deploy went successful

5. Access above resource 

Request URL

http://localhost:9080/mfp/api/adapters/testGuavaAdapter/resource

Response Body

Hello from guava resource 30

Response Code

200

Response Headers

{
  "x-powered-by": "Servlet/3.1",
  "content-type": "text/plain",
  "date": "Thu, 08 Jun 2017 11:48:32 GMT",
  "content-length": "28"
}

根据您的环境验证此工作原理。