-->

Building project.war file Via ant missed the files

2019-09-06 19:04发布

问题:

  1. I am creating project.war file using ant and worklight-ant-builder.jar file in the MFP.
  2. While my project is build using mfp or via eclipse in the bin the .war file and classes folder have all the things including content in my server->java folder.
  3. But when i build the ant file using step 1 i dont get the files in my server->java folder.

Note i have verified this by using 7-zip to see the contents in the .war file and also seen the folder classes created by the mobileFirst which contains server->java folder content when i use step 2.

Image Containing the peluk folder which is inside the Java->server->com ( Built using Step 2)

Image which dont have the peluk folder which is inside the Java->server->com (Built using Step 1)

I am using the following ant code.

 <taskdef resource="com/worklight/ant/defaults.properties">
            <classpath>
                <pathelement location="${res.location}\Resources\worklight-ant-builder.jar"/>
            </classpath>
        </taskdef>

        <war-builder projectfolder="bin"
                     warfile="bin\${proj.brcname}.war"
                     classesFolder="classes-folder"/>

回答1:

As @dhineshsundar mentioned in the comments: If you have custom Java code and you're planning on building a project using the Ant task script then you must first compile the Java code into a .class file and specify its location in the Ant task script. Then when building the project using the Ant task script it will also pick up the .class file.

The above does not happen automatically like it happens when using MobileFirst Studio.

See this user documentation topic: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.deploy.doc/devref/r_ant_tasks_deploy_projects.html

<?xml version="1.0" encoding="UTF-8"?>
<project name="myProject" default="all">
  <taskdef resource="com/worklight/ant/defaults.properties">
    <classpath>
      <pathelement location="cli_install_dir/public/worklight-ant-builder.jar"/>
    </classpath>
  </taskdef>
  <target name="all">
    <war-builder projectfolder="."
                 destinationfolder="bin/war"
                 warfile="bin/project.war"
                 classesFolder="classes-folder"/>
  </target>
</project>

The <war-builder> element has the following attributes:

  • The projectfolder attribute specifies the path to your project.
  • The destinationfolder attribute specifies a folder for holding temporary files.
  • The warfile attribute specifies the destination and file name of the generated .war file
  • The classesFolder attribute specifies a folder with compiled Java™ classes to - add to the .war file. .jar files in the projectfolder\server\lib directory are added automatically