If you need a Java build that does not require ritual sacrifice then Maven is your friend and your mild tormentor. This short Maven tutorial shows how to create a simple project folder structure add a minimal pom.xml declare dependencies and run a build with mvn so you get a runnable artifact without crying into your terminal.
Maven expects the conventional layout so give it what it wants. Create a project folder with these paths:
Using this layout avoids manual classpath work and keeps your CI pipeline from inventing new ways to fail.
Put a minimal pom at the project root. The pom tells Maven the group id artifact id and version and controls dependency resolution and the build lifecycle. Here is a tiny example you can paste and adjust.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
To add a library declare its groupId artifactId and version inside the dependencies block. Maven will fetch the jar from a remote repository and store it in your local cache so your project can compile against it. Transitive dependencies will also show up whether you meant them or not.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
Run the build with the usual command.
mvn clean package
That runs the default lifecycle phases including compile test and package and puts the output in the target folder. If you need a fat jar use a plugin such as the Maven shade plugin or the assembly plugin to bundle dependencies into a runnable jar.
From the project root run the jar like this.
java -jar target/myapp-1.0-SNAPSHOT.jar
If your jar is not runnable then double check your plugin config or your main class because Java is not psychic.
This tutorial covered project layout pom basics dependency declaration and the simple build and run sequence that gets a Java project from source to runnable artifact with minimal fuss. You now know where to put code how to declare dependencies how to build with mvn and how to run the jar. Go break something in CI and then fix it like a pro.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.