Episode 4, Build with Maven

Episode 4, Build with Maven

Season 1 - From Lame to Fame

  1. Go to your lameapp directory
  2. Create a text file with name pom.xml
  3. Use a simple text editor to edit pom.xml file (e.g. Notepad, Notepad++, Kate, Kwrite, Gedit, Nano, vim)
  4. Type the following content (no copy/pasting or a kitty will die):
    • OK, this part you can copy paste: <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">
<?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>tech.mecoming</groupId>
	<artifactId>lameapp</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<release>11</release>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>
  1. Save the file
  2. Create the following directory structure src/main/java/tech/becoming/lameapp
  3. Move LameApp.java to src/main/java/tech/becoming/lameapp
  4. Use a simple text editor to edit LameApp.java file (e.g. Notepad, Kate, Gedit, Nano, vim)
  5. Add this line at the beginning of the file package tech.becoming.lameapp;
    • Note tech.becoming.lameapp refers to src/main/java/tech/becoming/lameapp
  6. Go back to your original folder lameapp, where pom.xml is located
  7. Open here the terminal or cmd
  8. Type mvn clean package and hit Enter
  9. When BUILD SUCCESS, your app will be located under newly created directory called target/
    • The name of your app will be lameapp-0.0.1-SNAPSHOT.jar
    • Which equals to <artifactId> a dash and <version> tags from pom.xml
  10. Run the built app like this:
java -cp target/lameapp-0.0.1-SNAPSHOT.jar tech.becoming.lameapp.LameApp
You did it my friend, enjoy your little victory!

Homework

  1. You’ll need to read and practice this article Maven in 5 minutes
    • It’ll take you much more than 5 minutes
    • And you’ll not remember everything
    • But it is very important for you to practice it
  2. Then this Introduction to the Maven’s Standard Directory Layout