0
votes

I'm using WL 6.2.0.1 and one of our projects contains a Java files inside the WL server directory.

When I do the build for war file through eclipse I follow the following steps:

1- Right click on the project name > Build Project.

2- Right click on the project name > IBM Mobile Application Platform Pattern > Build Worklight EAR file.

Which generates to me the war file and inside it I see the java files.

When I switched to use ANT script to build the WAR file, I can't see the Java files anymore inside the war file:

ANT script:

<?xml version="1.0" encoding="UTF-8"?>
<project name="MobileApp" default="package" basedir="../">

<property name="WL_PATH" value="./buildscripts"/>
<property name="project.name" value="MobileApp"/>

  <taskdef resource="com/worklight/ant/defaults.properties">
    <classpath>
      <pathelement location="${WL_PATH}/worklight-ant6.2/worklight-ant-builder.jar"/>
    </classpath>
  </taskdef>
  <target name="WAR_CREATE">
    <war-builder projectfolder="${basedir}/temp/source/${project.name}"
                 destinationfolder="bin/war"
                 warfile="bin/MobileApp.war"
                 classesFolder="classes-folder"/>
  </target>
</project>

I'm not sure if I need to add the Java element to the script so it will compile the Java files. but I tried to add <Javac> but didn't work.

I referred to the following URL : https://ant.apache.org/manual/Tasks/javac.html. But Didn't know which one to use.

Any help thanks.

2

2 Answers

2
votes

XML

<?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>
  <path id="server-classpath">
            <fileset dir="..\jars\Resources" includes="worklight-jee-library.jar" />
            <fileset dir="..\jars\Resources\dev" includes="**/*.jar" />
  </path>
  <mkdir dir="bin\classes"/>
  <javac
      srcdir="${worklight.repositary}\${proj.brcname}\server\java"
      classpathref="server-classpath"
      destdir="bin\classes"
      verbose="true"
      includeantruntime="false"
      target="1.6"
    />
  <target name="all">
    <war-builder projectfolder="."
                 destinationfolder="bin/war"
                 warfile="bin/project.war"
                 classesFolder="bin\classes"/>
  </target>
</project>

The Above is the XML is used to Create a War file along with java classes.

Note :

In the places of dir , location and srcdir replace the content directory with your Locations.

0
votes

Unlike when using the Studio which automatically compiles any Java files that reside under the server\ folder, this does not happen when using the Ant task scripts.

You must first compile these files and point to the folder containing the resulting .class files. This pointing is done in the classesFolder attribute in the Ant task script.

For further elaboration see this answer by me: https://stackoverflow.com/a/30302415/1530814