Lab setup for building java projects
Create a free tier ubuntu vm on azure or aws
Tools helping Building java code
We have javac which is basic java compiler
For larger projects in very intitial phases, javac was used with make files
Apache Ant was introduced which helps in building java projects. Ant projects have build.xml which will have build instructions. The build.xml is configuration of what has to be done
Maven
Maven is a tool that is introduced to manage projects. Maven
manages dependencies
performs build, package, artifact management
create documentations
Maven uses Convention over Configuration model
Setup on Ubuntu
sudo apt install openjdk-17-jdk -y
sudo apt install maven -y
mvn --version
Simple maven commands mvn <goal>
mvn compile
mvn test
mvn package
Conventions:
We have created a pom.xml file with following content
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.learningthoughts.projects</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/s3 -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.31.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
We have created the folder structure src/main/java
Now execute mvn compile
To package mvn package
Projects skeleton or structure can be created using archetypes
mvn archetype:generate \
-DgroupId=io.learningthoughts \
-DartifactId=generated \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.5 \
-DinteractiveMode=false