DevOps Classroom Series – 11/Feb/2021

Building/Packaging the Code

  • In this series lets try to understand how to build java code
  • Building java code is executing the .java files with javac <> and then it creates .class file. Now to execute code java <pathto.class> Preview
  • In a enterprise software project, we will have multiple java files, so building each file to generate .class file and then combining .class files to build a jar file format is difficult
  • Apache ANT was the first famous tool which helped in building java code.
  • ANT build files are written in XML format.
  • Binary is the format that is packaged version of the code. It can be .exe file, .jar file, .dll file.
  • Lets install ant
  • Create a build.xml file in the source code and write build steps in xml file
<?xml version="1.0"?>
<project name="Hello World" default="info">
    <target name="info">
        <echo>Hello world - Welcome to Ant</echo>
  • Now navigate to the folder in terminal where you have build.xml file and execute ant Preview

  • Refer Here for the sample ant build.xml and steps

  • When we write code we use lot of external libraries which is referred as dependency. Generally for any enterprise project build includes managing dependencies.

Apache Maven

  • This is a software project managment and comprehension tool Refer Here

  • Maven is a tool which follows Convention over configuration

  • Some of the conventions are (${basedir} is the folder where you have your project)

    • source code => ${basedir}/src/main/java
    • resources => ${basedir}/src/main/resources
    • Test cases => ${basedir}/src/test
    • Class file => ${basedir}/target/classes
    • Jar/War => ${basedir}/target/
  • Installing maven

    • Windows: choco install maven
    • Linux: Refer Here
      • Ubuntu:
      sudo apt update
      sudo apt install openjdk-8-jdk -y
      sudo apt install maven -y
      • centos:
      sudo yum install java-1.8.0-openjdk -y
      tar xzvf apache-maven-3.6.3-bin.tar.gz
      sudo cp -r apache-maven-3.6.3 /opt
      # sudo vi /etc/environment
      export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-
      export PATH=$PATH:/opt/apache-maven-3.6.3/bin
    • mac: brew install maven
  • In Maven we create a pom.xml file where POM stands for Project Object Model. So our sample pom.xml

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  • Now lets move to the root folder of project and execute mvn compile and mvn package Preview Preview

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin