DevOps Classroom notes 28/Nov/2024

Java Build Tools

ANT

  • This was the tool created by Apache foundation
  • This build tool uses a configuration file called as build.xml
  • Ant works based on configuration
<?xml version="1.0"?>
<project name="MyAntProject" default="run" basedir=".">
    <property name="src.dir" location="src"/>
    <property name="build.dir" location="bin"/>
    <property name="jar.dir" location="dist"/>

    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${jar.dir}"/>
    </target>

    <target name="makedir">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${jar.dir}"/>
    </target>

    <target name="compile" depends="makedir">
        <javac srcdir="${src.dir}" destdir="${build.dir}"/>
    </target>

    <target name="jar" depends="compile">
        <jar destfile="${jar.dir}/MyAntProject.jar" basedir="${build.dir}">
            <manifest>
                <attribute name="Main-Class" value="test.Main"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar.dir}/MyAntProject.jar" fork="true"/>
    </target>
</project>

Maven

  • This is an opensource project hosted by apache
  • Design goal:
    • Convention over configuration
    • include dependency and release management
    • includes test execution
    • can be configurable
  • Maven build tool expects a file called pom.xml (project object model)
- src
  - main
     - java
         - *.java
  - test
     - java
         - *.java

pom.xml
  • POM (Project object model)
  • Goals:
    • clean: remove target folder
    • verify: (verify the pom and project)
    • compile: compile the java code and create class files in target folder
    • test: run the unit tests and generate xml reports
    • package: creates the package
    • install: copy the package and pom to local repo (~/.m2)
    • deploy: copy the package to remote repo
  • Maven will download dependencies in folder ~/.m2/repository
  • Installing Maven:
  • Lets build the spring petclinic using maven with command mvn package which will compile, run the tests and create the package
  • in some projects we will see mvnw files these are called as maven wrappers, they install necessary version of maven and execute goal
  • Central, Remote and Local Repos in Maven

Installing jdk

  • JDK comes in different flavors
    • openjdk
    • eclipse temurin
    • amazon correto
    • oracle jdk
  • to install openjdk 17 on ubuntu
sudo apt update
sudo apt install openjdk-17-jdk
java -version
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%