Mini project: the shoplite-console Maven project
60 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)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.
$ ./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, artifactIdshoplite-console, version0.1.0-SNAPSHOT, Java 17 (maven.compiler.release) and UTF-8 sources. - 2Code lives in the packages
com.shoplite.app,.model,.dao,.serviceand.config, each with apackage-info.javathat says what belongs there. - 3
com.shoplite.model.Productis a record with the columns of theproductstable; it rejects a blank sku or name, a price of 0 or less and negative stock. - 4
ProductTest(JUnit Jupiter 5.14.4, test scope) checks a valid product and both rejections, and./mvnw testpasses. - 5
./mvnw compile exec:javarunscom.shoplite.app.Main, and./mvnw packagebuildstarget/shoplite-console.jarthat runs withjava -jar. - 6The repository has the Maven Wrapper, a
.gitignorefortarget/, 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.classproperty.
Milestones
0/5 done · commit and push after each oneCreate the Maven project
mvn -q compilesucceeds in a newshoplite-consolefolder with the solution's pom.Add the packages, Product and a placeholder Main
mvn -q compile exec:javaprints the three ShopLite lines from the sample run.Write ProductTest and run it
./mvnw test(ormvn test) shows Tests run: 3, Failures: 0.Run with exec:java and build a runnable JAR
java -jar target/shoplite-console.jarprints the same three lines.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.
Add a
.gitattributesfile withmvnw text eol=lfso the shell script keeps Unix line endings on every computer.· easyAdd a
Categoryrecord (categoryId, name, parentId asIntegerbecause it can be null) with its own test.· mediumPrint the app version from the pom instead of the hard-coded
0.1.0.· mediumAdd a GitHub Actions workflow that runs
./mvnw -B verifyon every push.· hard
Solution
Opens when you add your repository link.
Finish up
Mark complete & continue
Next: What JDBC is: API and driver