Use this procedure to create and build a Java application with Apache Maven.
Procedure
- Create a makefile for your application.
For example, consider the following
example
hello/hello.mak
file.
POM_FILE := $(word 1,$(wildcard $(foreach d,$(APPL_ROOT),$d/hello/pom.xml)))
SRC_DIRS := $(wildcard $(foreach d,$(APPL_ROOT),$d/hello/src))
MVN_BLD_DIR := $(word 1,$(APPL_ROOT))/hello/gen
include maketpf.rules_maven
The
maketpf.rules_maven
file defines a default set of makefile rules to compile a Maven project with the maketpf utility.
This example specifies the minimum required variables and uses GNU make functions to traverse the
APPL_ROOT set of directories to search for the files and directories that are
specified by the variables:
- POM_FILE: The absolute path of the Maven application POM configuration file. This file must
already exist.
- SRC_DIRS: A list of directories to copy source from, ordered from the highest precedence to the
lowest. Each directory must already exist.
- MVN_BLD_DIR: A writable location where the maketpf utility can copy the source to and redirect
the Maven build output.
In addition, the following optional variables provide the capability to use and maintain a
layered Maven repository with the
MakeTPF build solution:
- MVN_REPO_DIRS: A list of directories to treat as repository locations when the application tries
to resolve dependencies. These directories do not have to exist.
- MVN_REPO_ADD: Specifies whether you want this Maven project to be contributed to the top layer
of the repository. If you set this variable to YES, at least one writable location
is required for the MVN_REPO_DIRS variable.
- Add a Maven POM configuration file and any source files to the appropriate locations
under the TPF_ROOT or APPL_ROOT directories as defined in the makefile.
- Update the user control file and user load file with a new entry for the
application.
- Edit the control file and add an entry for your application.
For
example, add the following entry for the
hello example
application:
hello;JAR;hello/hello.mak;1;ALL;OBJ;TPF_SBALL;NOLOAD;;;;;;;;;;;;;;;;;;;;;;;;;;
- Edit the load file and add entries for the names of your application and any
dependencies the application might have.
For example, add the following entries for
the
helloworld.jar example application and all of its dependencies under the
hello/gen/lib
directory:
hello/gen/helloworld.jar;/sys/tpf_pbfiles/apps/hello;644;tpfdfltu;tpfdfltg;BINARY;ALL;TPF_SBALL;LOAD;;;;;
hello/gen/lib/*;/sys/tpf_pbfiles/apps/hello;644;tpfdfltu;tpfdfltg;BINARY;ALL;TPF_SBALL;LOAD;;;;;
The control file entry is required to build the Maven application. The load file
entries are required to load the application and its dependencies.
- Enter the maketpf command to build the application.
For
example:
maketpf hello
- Specify additional maketpf configuration options or build targets as needed to help
diagnose any build issues.
- Set the MAKETPF_MSG_LEVEL option to control the amount of information messages that
are generated by Maven. For more information about maketpf configuration options, enter
man maketpf.cfg on your Linux® on IBM Z® build system.
- Run the checkenv target to display the build variables and values that are associated
with the Maven application. For more information about maketpf targets, enter man
maketpf on your Linux on IBM Z build
system.
What to do next
The maketpf utility can enhance the build experience across multiple Apache Maven applications by
automatically using a POM configuration to reference commonly defined Maven properties. The
maketpf.rules_maven_tpf_properties file contains a list of common version
properties that are used across the
z/TPF system. The
maketpf.rules_maven_user_properties file contains any application-specific
properties to be reused. Properties that are defined in these files can be freely referenced by any
Maven application without additional configuration changes. For example:
- Define a common property such as the following example in the
maketpf.rules_maven_tpf_properties
file:
tpf.log4j.version=2.17.1
- Update all POM configuration files to use the common property variable. For
example:
<dependency>
<groupId>org.apache.logging.log4j<groupId>
<artifactId>log4j-api</artifactId>
<version>${tpf.log4j.version}</version>
</dependency>