Skip to lesson

Mini project: the shoplite-console Maven project

shoplite-console is the Java console app for the ShopLite store that grows through this whole JDBC section, so it starts with the structure a real team would use: a Maven project with clear packages, a test, a runnable JAR and a clean first commit on GitHub.

What you'll build

You start from nothing but your JDK, Maven, Git and a GitHub account (the Git and Developer Setup section). You create the shoplite-console Maven project: groupId com.shoplite, Java 17, the packages model, dao, service, config and app, a Product record that matches the products table from the SQL section, a placeholder Main, and a JUnit test.

The build runs the tests, ./mvnw compile exec:java runs the app during development, and ./mvnw package makes target/shoplite-console.jar, which runs with java -jar. A .gitignore keeps build output and secrets out of Git, and the README explains how to build and run it. The next module connects this project to the shoplite MySQL database.

Sample run (timings and paths will differ)
$ ./mvnw clean package
...
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.shoplite.model.ProductTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.269 s -- in com.shoplite.model.ProductTest
[INFO] Results:
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- jar:3.5.0:jar (default-jar) @ shoplite-console ---
[INFO] Building jar: C:\Users\asha\projects\shoplite-console\target\shoplite-console.jar
[INFO] --- shade:3.6.2:shade (default) @ shoplite-console ---
[INFO] Replacing original artifact with shaded artifact.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
$ java -jar target/shoplite-console.jar
ShopLite console 0.1.0
Sample product: SL-RICE-5KG | Basmati Rice 5 kg | Rs 649.00 | stock 40
Database: not connected yet
$ ./mvnw -q compile exec:java
ShopLite console 0.1.0
Sample product: SL-RICE-5KG | Basmati Rice 5 kg | Rs 649.00 | stock 40
Database: not connected yet

Requirements

  • 1The project is a Maven project with groupId com.shoplite, artifactId shoplite-console, version 0.1.0-SNAPSHOT, Java 17 (maven.compiler.release) and UTF-8 sources.
  • 2Code lives in the packages com.shoplite.app, .model, .dao, .service and .config, each with a package-info.java that says what belongs there.
  • 3com.shoplite.model.Product is a record with the columns of the products table; it rejects a blank sku or name, a price of 0 or less and negative stock.
  • 4ProductTest (JUnit Jupiter 5.14.4, test scope) checks a valid product and both rejections, and ./mvnw test passes.
  • 5./mvnw compile exec:java runs com.shoplite.app.Main, and ./mvnw package builds target/shoplite-console.jar that runs with java -jar.
  • 6The repository has the Maven Wrapper, a .gitignore for target/, IDE files and secret settings files, and a README with build and run steps.
  • 7Plugin versions are pinned and the main class is written once, in the main.class property.

Milestones

0/5 done · commit and push after each one
  1. Create the Maven project

    mvn -q compile succeeds in a new shoplite-console folder with the solution's pom.

  2. Add the packages, Product and a placeholder Main

    mvn -q compile exec:java prints the three ShopLite lines from the sample run.

  3. Write ProductTest and run it

    ./mvnw test (or mvn test) shows Tests run: 3, Failures: 0.

  4. Run with exec:java and build a runnable JAR

    java -jar target/shoplite-console.jar prints the same three lines.

  5. Wrapper, .gitignore, README and the first push

    GitHub shows the project with pom.xml, mvnw, src and README, and no target folder.

Build it in your own GitHub repository and push after each milestone. When everything works, mark the project as complete.

Extra challenges (optional)

Do any you like, each on its own branch, so your main project keeps working.

  1. Add a .gitattributes file with mvnw text eol=lf so the shell script keeps Unix line endings on every computer.· easy

  2. Add a Category record (categoryId, name, parentId as Integer because it can be null) with its own test.· medium

  3. Print the app version from the pom instead of the hard-coded 0.1.0.· medium

  4. Add a GitHub Actions workflow that runs ./mvnw -B verify on every push.· hard

Solution

Opens when you add your repository link.

Finish up

Mark complete & continue

Next: What JDBC is: API and driver