7.3. Updating the POM¶
By default, the maven-archetype-quickstart
archetype (version
1.4
) is configured to use Java 7 (1.7
)! We can remedy this by
updating the project’s pom.xml
file using Emacs.
Change into the
cs1302-mvn
directory, then change the values of themaven.compiler.source
andmaven.compiler.target
to17
for Java 17. It should look similar to the following:<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties>
That’s it! After making that change, your project is now set up to use Java 17.
You can also add/update project dependencies. In the past, you may have done this by manually including a JAR file on your classpath. With Maven, we can add the dependency in the POM and Maven will download the necessary JAR file and add it to the classpath for us! For example, the
pom.xml
file in yourcs1302-mvn
project already contains the following dependencies:<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
This adds a dependency called JUnit 4.11 To add more dependencies, you would simply add an additional
<dependency></dependency>
tag with appropriate values before the closing</dependencies>
tag. Many libraries are packages for Maven. You can try searching for some on Maven Central.When using Maven with your JavaFX projects, you would need to add the JavaFX 17 dependency to your
pom.xml
file. Adding this dependency to the existingjunit
dependency would look like this:<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>17.0.2</version> </dependency> </dependencies>