Maven is a lightweight distributed tool. Hence it does not have any specific hardware requirement.
Following are steps to install Maven on Windows platform.
It is developed in JAVA language. Hence it will need Java Virtual machine installed as software requirement. To check that JVM is installed on your machine, run following command. It should print the JDK version on your machine. If it does not print, follow link to install JVM
C:\Users\guest>java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
Every software developer works with Integrated development environments (IDE) like eclipse, netbeans, MS Visual Studio etc. It gives them easy way to write code, that helps. Perhaps while building a project into distribution package, simple IDE may not be of help, since role of IDE is to support individual developer and not the project team.
Hence there comes need of build tool, which would automate several tasks of build process like shutdown servers, compile code, automate tests and generate reports etc. Maven can be viewed as build tool that can help us address these areas with industry standard and industry supported plugins.
However, Maven is more than a build tool. It can do automatic dependency resolution and distribution. It can help manage project source tree across different teams and repositories. It can generate ready to start framework with respect to type of architecture say simple java project that distributes JAR, simple web application that distributes WAR or complex enterprise application that distributes EAR.
Maven is open source tool backed by vast community. It is basically a plugin framework, with extensive set of ready made plugins which we can use or we can write custom one that solves specific problem of life. Hence it is extensible as well.
Several IDEs too support maven. For sake of simplicity and my family of JAVA, we will use eclipse to demonstrate the maven.
Above link provides detailed developers documentation about all capabilities of ant build. It can give detailed documentation about syntax, procedures, what are all in built tasks available, how to create customized tasks, how to configure Ant with various development IDEs etc.
In previous tutorial, we have set several paths hardcoded in buildConfig configuration file. However Ant provides capability to either declare those values as properties in configuration file, load values from resource file or pass resource key-value pairs from command line. We will use same buildConfig file to modify it.
1.Declare Values as Properties in configuration file:
We have cleanLogs target in buildConfig file, which is receiving directory path to delete files within. Lets declare that path as property value in beginning of path, like below
Target can be seen as module of tasks in ant configuration file. We can request ant to execute specific target, by passing command line input. Each target may have one or more tasks. Following is sample buildConfig.xml
Exec as Target : please refer target named “stopOracle” having exec as task tag inside. It contains executable command to stop oracle service. if we pass this as target it will stop oracle databse service named “OracleServiceORCLDB”. Similarly we have “startOracle” to start the oracle database instance service.
Dependent Target : Target “deleteLogs” is having dependency on “stopOracle” target. Hence if we execute “deleteLogs” target, it will first invoke “stopOracle”, then its own tasks are executed.
Multiple Tasks : If we want two or more tasks to be executed together as single module, multiple tasks can be mentioned in single target. Target “compileSource” contains the two tasks compile .java files and also create the jar of compiled classes.
Following is HelloWorld configuration file “buildConfig.xml”. File can have any name. Open command prompt and copy file in current directory.
<?xml version="1.0"?>
<project name="AntDemo" default="hello">
<target name="hello">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
</project>
Execute following Ant command
>ant -buildfile buildConfig.xml hello
As seen in command, we are invoking ant.bat having two command line parameters -buildFile and target to execute in the build file.
In the buildConfig.xml target “hello” is mentioned and invoked. Target “hello” consists of single in-built task echo to print the input message in config file.
It prints output on console by default. Each target is executed & printed on console. Here “hello:” target is executed & printed on console its output that is echo message. In the end it says “BUILD SUCCESSFUL” with return code 0.
Ant has several optional input parameters, that can be seen using following command
Check that compatible java version is already installed on local machine & environment variable JAVA_HOME is already set. Following commands can help to check that.
Unzip the Ant downloaded distribution package
Set environment variable ANT_HOME pointing to base directory of unzipped ant distribution.
Add new entry in PATH environment variable, to add path of ant bin directory.
To check if ant is successfully installed, open command prompt and type command “ant -version”, it should show installed version of ant.
Ant is open source build framework provided by Apache Foundation, based on Java. At can help us to automate day to day tasks mainly for software build procedure. It can also serve as developer tool to automate day to day mundane tasks like start-stop services, delete logs, update database, codebase etc.
Ant takes XML configuration file as input build File. Build file contains the tags based instructions on what & how to perform certain tasks.
Build file may mention more than one target definitions. Each target may have one or more tasks to perform. Target can be passed as another input to Ant script, to instruct which target to perform. Target may have dependency on some other targets. In such case, dependency targets are executed first, followed by tasks in current target.
Each target may have one or more tasks to perform like copy files, delete files, compile, execute etc. Tasks are in built tag definitions of Ant. Ant provides rich set of inbuilt tasks viz copy, delete, echo, exec etc. Those in built tasks can be used passing attributes as their inputs. Also customized ant tasks can also be developed.
XML based build file may be viewed as static configuration. For dynamic configurations, input values can be passed through command line arguments or resource files.