MFP CLI 无法构建部署最初使用 MFP Studio 创建的项目

MFP CLI cannot build-deploy project initially created with MFP Studio

问题背景:
我们最初使用 Eclipse 的 MFP Studio 插件在 iOS 环境中创建了一个 MFP 混合项目。我们将这个项目置于源代码控制之下(Git on DevOps)。我们团队中的一些团队成员正在为此项目进行 iOS 开发,由于他们不熟悉 Eclipse,因此他们想改用 CLI。同一团队中的其他开发人员将继续使用 Studio,因为他们正在为 MFP 适配器编写 Java 代码并希望利用 Eclipse 提供的功能,例如编译、代码自动完成等。

问题:
从 Git 拉取 MFP 项目代码后(fresh pull),如果首先使用 Studio 来“Build All Environments”和“运行 on MobileFirst Platform”,那么我们可以 运行 MFP 应用程序没有任何问题。然后我们还可以切换到 CLI 来构建和部署工件,CLI 命令工作得很好。

现在,假设从 Git 中提取代码(fresh pull),而不是使用 Studio,我们立即开始使用 CLI 来构建和部署工件。在这种情况下,CLI 会抛出错误。 CLI 似乎缺少 Studio 知道如何执行的步骤。在从 Git 重新拉取后立即使用 CLI 构建和部署 (mfp bd) 时出现的错误如下:

$ mfp bd 
All apps and adapters were successfully built.  
Initializing MobileFirst Console.

BUILD FAILED
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:147: Compile failed; see the compiler error output for details.

Total time: 1 second
Error: Build process failed. Please check the stack above for details.

BUILD FAILED
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:380: Element <project> inside <configureApplicationServer>: File '/Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp/bin/HatchReadyApp.war' does not exist.

Total time: 1 second
Error: Build process failed. Please check the stack above for details.
objc[81801]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Starting server worklight.
Server worklight started with process ID 81800.
    [wladm] Unexpected response from http://192.168.1.126:10080/worklightadmin/management-apis/1.0/runtimes/HatchReadyApp/adapters?locale=en_US:
    [wladm] <?xml version="1.0" encoding="UTF-8"?>
    [wladm] <deploy-adapter-result ok="false" productVersion="6.3.0.00-20150214-1702">
    [wladm]   <transaction id="168" type="UPLOAD_ADAPTER" status="FAILURE" timeCreated="2015-04-13T13:53:18.599Z" timeUpdated="2015-04-13T13:53:18.870Z" userName="admin" appServerId="Liberty">
    [wladm]     <project name="HatchReadyApp"/>
    [wladm]     <description filename="SBBAdapter.adapter" name="SBBAdapter" alreadyDeployed="false"/>
    [wladm]     <errors>
    [wladm]       <error mbeanName="com.worklight.common.server.jmx.api:qualifier=HatchReadyApp,type=ProjectManagement" date="2015-04-13T13:53:18.831Z" phase="PREPARE" code="FAILURE" exception="RuntimeException" details="Runtime synchronization failed. Cannot deploy adapter to runtime"/>
    [wladm]     </errors>
    [wladm]     <warnings/>
    [wladm]   </transaction>
    [wladm] </deploy-adapter-result>

Error: The MobileFirst server that you have configured does not appear to be running. Start the server with 'mobilefirst start'.

更多详情:

如果我在执行 'mfp bd' 之前先启动 MFP 服务器,它也会失败并出现类似的错误:

$ mfp start
Initializing MobileFirst Console.

BUILD FAILED
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:147: Compile failed; see the compiler error output for details.

Total time: 1 second
Error: Build process failed. Please check the stack above for details.

BUILD FAILED
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:380: Element <project> inside <configureApplicationServer>: File '/Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp/bin/HatchReadyApp.war' does not exist.

Total time: 1 second
Error: Build process failed. Please check the stack above for details.
objc[55444]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Starting server worklight.
Server worklight started with process ID 55443.

MFP 信息输出:

$ mfp info
OS: darwin x64
Release: 14.1.0
System Memory: 89MB free out of 16384MB
Node: v0.10.30
MobileFirst CLI: 6.3.0.00.20150214-1708
Current directory: /Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp

Current project: /Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp

Adapter: getOffers (/Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp/adapters/SBBAdapter/SBBAdapter.xml)
Description: SBBAdapter
Type: http
Procedures: test, getUser, getAccounts, getTransactions, getGoals, getDashboardData, getFeasibility, submitAuthentication, getTradeoffSolution, getOffers

Application: Hatch (/Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp/apps/Hatch/application-descriptor.xml)
Description: Hatch
Type: hybrid application
Features: 
Environments: iphone
Skins: 

Server location: /Users/olivieri/.ibm/mobilefirst/6.3.0/server
Server binary: /Users/olivieri/.ibm/mobilefirst/6.3.0/server/wlp/bin/server
MobileFirst instance: /Users/olivieri/.ibm/mobilefirst/6.3.0/server/wlp/usr/servers/worklight
objc[85669]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
WebSphere Application Server 8.5.5.3 (1.0.6.cl50320140731-0257) on Java HotSpot(TM) 64-Bit Server VM, version 1.7.0_51-b13 (en_US)

Environment variables:
TERM_PROGRAM: Apple_Terminal
ANDROID_HOME: /Users/olivieri/android-sdks
SHELL: /bin/bash
TERM: xterm-256color
TMPDIR: /var/folders/c9/gf_f0_sd60q1mm9kxwgvlxsr0000gn/T/
Apple_PubSub_Socket_Render: /private/tmp/com.apple.launchd.JKtd63AtGc/Render
TERM_PROGRAM_VERSION: 343.6
TERM_SESSION_ID: D5FA1866-C7B1-4AC0-A045-B8BD0AF18A5D
ANT_HOME: /Users/olivieri/Development/apache-ant-1.9.4
USER: olivieri
SSH_AUTH_SOCK: /private/tmp/com.apple.launchd.ECR6tzx7Xe/Listeners
__CF_USER_TEXT_ENCODING: 0x1F5:0x0:0x0
PATH: /Users/olivieri/Development/apache-ant-1.9.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/IBM/MobileFirst-CLI:/Users/olivieri/Development/gradle-1.12/bin:/Users/olivieri/android-sdks/tools:/Users/olivieri/android-sdks/platform-tools
PWD: /Users/olivieri/git/Ready.App.3.Hatch/HatchReadyApp
LANG: en_US.UTF-8
XPC_FLAGS: 0x0
XPC_SERVICE_NAME: 0
SHLVL: 2
HOME: /Users/olivieri
LOGNAME: olivieri
DISPLAY: /private/tmp/com.apple.launchd.8nfQqEAeMS/org.macosforge.xquartz:0
_: /Applications/IBM/MobileFirst-CLI/IBMnode/bin/node
WLP_USER_DIR: /Users/olivieri/.ibm/mobilefirst/6.3.0/server/wlp/usr

感谢帮助我们解决此问题的 IBM 人员。要解决此问题,我们必须对以下文件进行两项更改:/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml

我们 [在此文件中] 替换了以下两个部分,如下所示:

1)

 <!--
  <path id="server-classpath">
    <fileset dir="${worklight.jars.dir}" includes="worklight-jee-library.jar" />
    <fileset dir="${worklight.server.install.dir}/wlp/dev" includes="**/*.jar" />
  </path>
 -->

  <path id="server-classpath">
    <fileset dir="${worklight.jars.dir}" includes="worklight-jee-library.jar" />
    <fileset dir="${worklight.server.install.dir}/wlp/dev" includes="**/*.jar" />
    <!-- add server/lib folder to classpath -->
    <fileset dir="${worklight.app.dir}/../server/lib" includes="**/*.jar" />
  </path>

2)

<!--
  <target name="build-WAR" description="Build worklight WAR for project">
    <echo message="Building worklight WAR for project ${ProjectName}" />
    <javac
      srcdir="server/java"
      destdir="bin/classes"
      classpathref="server-classpath"
      verbose="true"
      includeantruntime="false"
    />
    <war-builder
      projectfolder="${basedir}"
      destinationfolder="bin/war"
      warfile="bin/${ProjectName}.war"
      classesfolder="bin/classes">
    </war-builder>
  </target>
-->

<target name="build-WAR" description="Build worklight WAR for project">
    <echo message="Building worklight WAR for project ${ProjectName}" />
    <!-- first clear out the existing bin/classes contents -->
  <delete includeemptydirs="true">
    <fileset dir="bin/classes" includes="**/*"/>
  </delete>
    <javac
      srcdir="server/java"
      destdir="bin/classes"
      classpathref="server-classpath"
      verbose="true"
      includeantruntime="false"
    />
    <if>
      <available file="server/java/resources" />
      <then>
        <!-- now copy the contents of server/java/resources into bin/classes so they get included in the war -->
      <copy todir="bin/classes/resources" failonerror="false">
        <fileset dir="server/java/resources"/>
      </copy>
      </then>
    </if>
    <war-builder
      projectfolder="${basedir}"
      destinationfolder="bin/war"
      warfile="bin/${ProjectName}.war"
      classesfolder="bin/classes">
    </war-builder>
  </target>

进行上述更改后,我们可以 运行 'mfp restart' 和 'mfp bd' 命令而不会出现任何错误。