Java, Maven

make things

We will use Java 21 for our projects and Maven for compiling source files, managing dependencies, and assembling executables.

Using Maven with IntelliJ When you create your project, select Maven as the Build system. IntelliJ will generate a file named pom.xml in the project. The pom file specifies the settings and information used by maven to compile, test, and package your project. Initially, it will look like this:

    <?xml version="1.0" encoding="UTF-8"?>

    <project xmlns="http://maven.apache.org/POM/4.0.0"


             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">














For this project, edit the groupId to be com.neu.halp; all of the Java you write in this class should be in the com.neu.halp package, or a subpackage.

Adding Dependencies You may also use the "New Dependency" option in IntelliJ’s "Generate" wizard. To use an external library with your project, such as JUnit, it must be specified in your pom. To do this, we must specify the library and its version in a dependencies list:






When we edit the pom in the IDE, we must tell IntelliJ to take note: You can also use the "Reload All Maven Projects" button in the Maven tool window.

load Maven changes

Building an Executable To build an executable JAR, we will use the Maven assembly plugin. Instructions for the plugin go in the build section of the pom. The example below calls for the creation of a JAR named MyExecutable.jar. When we run java -jar MyExecutable.jar, it invokes the main method of the MyMain class in the com.neu.halp package. Executing the package goal will attempt to assemble the executable.