Agentic AI with Java: Live Cohort
MavenMaven Projects & Goals

Maven Java Project Linux VM

Generate the same Maven Java project on the Amazon Linux VM, inspect it with ls and tree, and understand the Maven standard directory layout that every project follows.

The command from the previous lesson is exactly the same on Linux. What changes is how you look at the result: there is no File Explorer to double click through, so you explore the project with ls, cd and a handy tool called tree. If you are practising only on Windows, you can skip this lesson. The directory layout section at the end is useful for everyone, though.

Generate the project

SSH into your EC2 instance (see Maven Installation on Cloud Linux VM), confirm Maven is there, and run the generator:

mvn -v
clear

mvn archetype:generate \
  -DgroupId=com.telusko \
  -DartifactId=telusko-app \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DarchetypeVersion=1.5 \
  -DinteractiveMode=false

The backslash \ at the end of a line tells Bash that the command continues on the next line. You can also paste it all on one line.

To recap the parameters (full table in Maven Java Project):

ParameterValueMeaning
groupIdcom.teluskoOrganisation, reverse domain name, also the Java package
artifactIdtelusko-appProject name, folder name, and the start of the JAR name
archetypeArtifactIdmaven-archetype-quickstartTemplate for a simple standalone Java project (JAR)
archetypeVersion1.5Version of the template. The video uses 1.0, which also works but generates an older POM
interactiveModefalseDo not prompt, use these values

On a fresh VM the first run downloads plugins from Maven Central, so expect a long list of Downloading from central lines followed by BUILD SUCCESS.

Look inside

ls -l
# drwxr-xr-x. 3 ec2-user ec2-user 32 Jul 28 11:38 telusko-app

cd telusko-app
ls -l
# -rw-r--r--. 1 ec2-user ec2-user ... pom.xml
# drwxr-xr-x. 4 ec2-user ec2-user ... src

Two things, as on Windows: pom.xml (how you talk to Maven) and src (your code). Moving through src/main/java/com/telusko one cd at a time is slow, so install tree, which prints the whole folder structure at once:

cd ~
sudo dnf install -y tree
tree telusko-app
Output of tree telusko-app showing pom.xml, src/main/java/com/telusko/App.java and src/test/java/com/telusko/AppTest.java

The tree output on the VM. Generated with archetype 1.0 in the video, so there is no .mvn folder.

The video runs sudo tree telusko-app. sudo is not needed here: the files belong to ec2-user, so a normal tree can read them. Only installing the package needs sudo. Getting into the habit of using sudo only when you must is a good security practice.

If you prefer an editor, vi pom.xml opens the POM (press Esc then type :q to quit). The vi editor basics lesson in the Linux course covers the keys you need.

The Maven standard directory layout

Whatever you used to create it (terminal, IntelliJ, Eclipse), every Maven project follows the same layout. Once a build runs, a target folder joins it.

Maven standard directory layout: pom.xml, src/main/java, src/main/resources, src/test/java, src/test/resources and target
PathContentsEnds up in the JAR?
pom.xmlProject descriptorA copy goes into META-INF/maven/
src/main/javaApplication source codeYes, compiled to .class
src/main/resourcesConfig files, properties, XML, templatesYes, copied as is
src/main/webappJSP, HTML, WEB-INF/web.xml for web appsYes, inside a WAR
src/test/javaUnit test source codeNo
src/test/resourcesConfig files used only by testsNo
target/Everything Maven generates: classes, reports, the JAR or WARIt is the output. Never commit it to Git

Add target/ to .gitignore

target/ can always be regenerated by running a build, and it often holds large files. Every Maven project should have target/ in its .gitignore. See Cloning repos and .gitignore in the Git course.

Try It Yourself

  1. Generate telusko-app on the VM and print its structure with tree.
  2. Run find telusko-app -name "*.java" and compare the result with the tree output.
  3. Create src/main/resources with mkdir -p telusko-app/src/main/resources and add an app.properties file. Run tree again.
  4. Generate a second project with -DartifactId=calculator-app and confirm the folder name and package match your parameters.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on