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