Start learning free

LESSON 147 OF 173 · BACKEND: SHIPPING IT

pom.xml in Java

Practice

On your computer, Maven downloaded the shop's packages one day and keeps them in a folder of yours. A server starts empty. To build the shop there, Maven downloads the packages listed in a file named pom.xml, inside <dependencies>: one <dependency> per package, with its groupId (who makes it), its artifactId (its name) and its version.

An exact <version> pins the package: Maven downloads exactly that version, on every machine, not whatever is newest on the day it runs. Spring Boot's own packages need no version line: the parent at the top of the file, spring-boot-starter-parent 3.3.5, pins them. Classes that come with Java, like java.util.Map, stay out of the file. Here is a dependency of another project, a small bot that sends a newsletter:

<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.11.0</version>
</dependency>

In this lesson the file's text is a Java array of strings, pom: one string per line of the file, each followed by a comma. The check prints the file, then reads it the way Maven would and prints:

mvn dependency:go-offline:
spring-boot-starter-parent 3.3.5: the parent; it pins the versions of Spring Boot's own packages
spring-boot-starter-web 3.3.5: the version the parent pins, on every machine
spring-boot-starter-jdbc 3.3.5: the version the parent pins, on every machine
sqlite-jdbc 3.46.1.3: this exact version, on every machine
The shop needs spring-boot-starter-web (the routes, and Tomcat, the web server that runs them): 3.3.5, pinned by the parent
The shop needs spring-boot-starter-jdbc (JdbcTemplate comes with it): 3.3.5, pinned by the parent
The shop needs sqlite-jdbc (the driver behind jdbc:sqlite:shop.db): pinned to 3.46.1.3

Your task: the parent and the build are already written. Inside <dependencies>, add the three packages the shop needs: spring-boot-starter-web (the routes, and Tomcat, the web server that runs them) and spring-boot-starter-jdbc (JdbcTemplate), both from org.springframework.boot with no version line, and the SQLite driver sqlite-jdbc from org.xerial, pinned to 3.46.1.3.


Assignment
Follow the Coding Tutorial to add the shop's three dependencies to pom, the text of its pom.xml.


Hint
Each line of the file is one string in the array, with a comma after its closing quote. Write a dependency's opening and closing lines first, then the lines between them.


STEP 1 OF 7
    Ctrl + Enter to check

    Ship Requirements in Java

    Keep going with Java1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free