To Build a Project Using Apache Ant

Visual COBOL uses an Apache Ant script, .cobolBuild, to build COBOL projects. This script is automatically generated from the .cobolProj project file.

Existing external build scripts such as makefiles, MSBuild, shell scripts and others can build COBOL applications using .cobolBuild as an Ant build file.

If you use an Ant file from a project developed on a remote machine using the Visual COBOL Development Hub, the application is built on the machine running Ant. This is how you use .cobolBuild to perform a full build of a project:
From a Windows command prompt:
ant -lib %ProgramFiles(x86)%\Micro Focus\Visual COBOL\bin\mfant.jar -f .cobolBuild
From a UNIX command prompt:
ant -lib $COBDIR/lib/mfant.jar -f .cobolBuild

You can compile your source code faster on multi-CPU machines if you use parallel compilation. To do this, you must add the threadCount=nn parameter. Where nn specifies the number of CPU threads to use:

From a Windows command prompt:
ant -lib %ProgramFiles(x86)%\Micro Focus\Visual COBOL\bin\mfant.jar -f .cobolBuild -DthreadCount=2
From a UNIX command prompt:
ant -lib $COBDIR/lib/mfant.jar -f .cobolBuild -DthreadCount=2
Restriction: Multi-processor compilation of the sources in a project is only supported for native COBOL. It is not recommended to use with native Object-Oriented COBOL applications.
To perform an incremental build:
From a Windows command prompt:
ant -lib %ProgramFiles(x86)%\Micro Focus\Visual COBOL\bin\mfant.jar -f .cobolBuild -DforceCompile=false
From a UNIX command prompt:
ant -lib $COBDIR/lib/mfant.jar -f .cobolBuild -DforceCompile=false
You can combine the threadCount and forceCompile parameters to perform a faster incremental build.
Note: When compiling to multiple executables from the command line, you must specify the -logger parameter to enable the correct log to be output to the console:
-logger com.microfocus.ant.CommandLineLogger
Alternatively, you can specify the -logger option as an environment variable as follows:

For Windows:

set ANT_ARGS=-logger com.microfocus.ant.CommandLineLogger

For UNIX:

export ANT_ARGS=-logger com.microfocus.ant.CommandLineLogger
From the Eclipse IDE:
  1. Click Window > Preferences > Run/Debug > Launching and clear the Build (if required) before launching option, if you do not want to trigger an Eclipse build before each Ant build.
  2. In COBOL Explorer, right-click the .cobolBuild file and click Run As > Ant Build.

You can set your own shell scripts as pre- or post-build events and they execute as part of the .cobolBuild Ant script before or after compiling.

To set pre- or post-build events:

  1. Right-click your project in the COBOL Explorer view and click Properties.
  2. Expand Micro Focus > Build Configurations and click Events for the desired configuration.
  3. Type the code of the script either in the Pre-build event command line or in the Post-build event command line field.
  4. Click Apply and then click OK.
Note:

If you reference variables in the Events field, you must prefix any linked resource path variables with ${pathVar. and terminate the variable with }. For example, code PROJECT_LOC as ${pathVar.PROJECT_LOC}.

Linked resources path variables are defined in the project's properties as follows:

  1. Right-click your project in COBOL Explorer, then click Properties > Resource > Linked Resources.
  2. See the variables listed on the Path Variables tab.