2017-06-07 56 views
0

在IBM MobileFirst 8.0中對使用Java適配器的外部庫有沒有限制?帶有外部庫的IBM MobileFirst適配器

當我加入guava我的代碼沒有錯誤(mfpdev適配器建立成功),但部署到我的服務器時,它與錯誤迴應:

[ERROR] Failed to execute goal com.ibm.mfp:adapter-maven-plugin:8.0.2016082422:deploy (default-cli) on project X: The output of /mfpadmin/management-apis/2.0/runtimes/mfp/adapters is of type text/html, which is unsupported. Expected an output of type text/xml or application/xml or application/json. -> [Help 1] 

當我刪除POM番石榴(MVN依賴)我可是我能夠部署適配器。我也可以看到其他一些圖書館也遇到問題。有沒有選擇使用這種庫?

mfpdev -v:8.0.0-2017012016

編輯

<scope>provided</scope> 
+0

你是怎麼把它加入到pom.xml中的? –

+0

由mvn依賴。 '<! - https://mvnrepository.com/artifact/com.google.guava/guava - > com.google.guava 番石榴 21.0 ' – 3squad

回答

0

我在MFP 8.0環境中嘗試這樣做,我終於在POM文件中設置範圍爲番石榴解決問題沒有看到問題。

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" 
} 

驗證此工作對你的環境。

+0

我的問題總是在我有依賴的番石榴時發生,即使我沒有在java代碼中使用它。如果我註釋掉番石榴的依賴關係,我可以在沒有任何問題的情況下部署適配器,但是當我添加這種依賴關係時,我不能。如您所見,「 – 3squad

+0

,我已經增加了依賴性,它可以工作,我使用的MFP服務器版本是最新的MFP8 產品版本:8.0.0.00-20170412-235541。你能否確認使用的MFP服務器版本,以及是否在pom.xml中添加了與hv相同的依賴關係? –

+0

我確信我相信。我通過設置範圍最終解決了問題:提供了依賴關係。 – 3squad

相關問題