Bluemix中也提供了IBM Watson™服務,本次實戰教程中,我們選擇text_to_speech服務。這裏我們講採用CLI命令行進行開發,如果沒有安裝clound foundry CLI,需要提前安裝一下,可參考http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-full-java.shtml進行準備工作。
第一步:我們先安裝ant
$ brew update
$ brew install ant
看到下面這段就說明安裝好了
==> Downloading https://www.apache.org/dyn/closer.cgi?path=ant/binaries/apache-a
==> Best Mirror http://apache.mirrors.hoobly.com/ant/binaries/apache-ant-1.9.4-b
######################################################################## 100.0%
�� /usr/local/Cellar/ant/1.9.4: 1597 files, 39M, built in 3.4 minutes
第二步:下載示例項目https://github.com/watson-developer-cloud/text-to-speech-java
下載zip文件解壓。(筆者嘗試導入Eclipse,發現有很多錯誤需要解決,可能有些配置不對,由於時間關係,所以採用命令行工具開發)
第三步:修改manifest.yml
---
declared-services:
text-to-speech-service:
label: text_to_speech
plan: free
applications:
- services:
- text-to-speech-service
name: text-to-speech-java-malajisi
path: output/webApp.war
memory: 512M
主要是修改services下面的應用名稱name一項,這個必須是唯一的。
第四部:編譯
$ ant build
出現下面的信息就說明成功了。
build:
BUILD SUCCESSFUL
Total time: 1 second
$ cf api https://api.ng.bluemix.net
cf login -u <你的bluemix賬戶ID>
根據提示輸入賬戶密碼
第六步:創建一個text_to_speech服務。
$ cf create-service text_to_speech free text-to-speech-service
第七步:push到bluemix服務器。
$ cf push
這個過程比較長,如果網絡不穩,有可能會中斷,出現下面的錯誤,不要灰心,重新執行一遍cf push命令即可。
-----> Downloaded app package (1.1M)
-----> Liberty Buildpack Version: v1.17-20150501-1729
-----> Retrieving IBM 1.7.1_sr2fp11ifx-20150312 JRE (ibm-java-jre-7.1-2.11-pxa6470_27sr2fp11ifx-20150312_01-rc4-sfj.tgz) ... (0.0s)
Expanding JRE to .java ... (0.7s)
-----> Retrieving App Management Agent 2015.03.09_101422 (com.ibm.ws.cloudoe.app-mgmt-proxy-agent.zip) ... (0.0s)
Expanding App Management to .app-management (0.0s)
-----> Retrieving com.ibm.ws.liberty-2015.4.0.0-201505011729.tar.gz ... (0.0s)
Installing archive ... (0.7s)
-----> Liberty buildpack is done creating the droplet
-----> Uploading droplet (113M)
FAILED
Error performing request: Get https://api.ng.bluemix.net/v2/apps/2c000380-c2e2-4e1d-864b-b93366aeec9b/instances: dial tcp 75.126.70.44:443: i/o timeout
-----> Uploading droplet (113M)
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App text-to-speech-java-malajisi was started using this command `.liberty/initial_startup.rb`
Showing health and status for app text-to-speech-java-malajisi in org****** / space First as*******...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: text-to-speech-java-*****.mybluemix.net
last uploaded: Wed May 20 14:42:32 UTC 2015
stack: lucid64
state since cpu memory disk details
#0 running 2015-05-20 10:45:03 PM 0.0% 140.2M of 512M 176.9M of 1G