Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Java
Stage 5: Specialization

Part 15 / Topic 7 of 7

Putting it together: package a CLI tool as a JAR, then as a Maven project

Real-world example: BillSplitter — a restaurant-bill-splitting CLI, splitting a total plus an optional tip equally across diners — built and packaged twice, the same source, two different ways:

  1. By hand (examples/jar-packaging/): javac to out/, jar --create --main-class ... -C out ., run with java -jar. No pom.xml, no dependency management — exactly section 2's technique, with a slightly more real CLI tool than the one-liner used to introduce it.
  2. With Maven (examples/maven-project/): the same logic, moved into src/main/java, with the pure calculation split into a separately-testable BillCalculator (one record Split(...), one static method) and a real BillCalculatorTest under src/test/java — then mvn package (section 4) produces a jar with an identical Main-Class manifest entry, runnable the same way.
# the hand-built jar (examples/jar-packaging/)
$ java -jar billsplit.jar 2400 4 10
Bill: Rs 2400.00
Tip (10.0%): Rs 240.00
Grand total: Rs 2640.00
Split 4 ways: Rs 660.00 per person

# the Maven-built jar (examples/maven-project/), same logic, same CLI, same output
$ java -jar target/bill-splitter-1.0.0.jar 2400 4 10
Bill: Rs 2400.00
Tip (10.0%): Rs 240.00
Grand total: Rs 2640.00
Split 4 ways: Rs 660.00 per person

Nothing about the program's behavior changes between the two — a java -jar call can't tell which build tool, if any, produced the jar it's running. What changes is everything around the program: Maven adds a repeatable build command, a place for tests to live and run automatically before packaging, and a standard layout any other Maven user already recognizes — exactly the gap section 1 opened with.

Done here? The practice set for Part 15 — including the solutions — is on the part page.

Search the guide