====== Maven Example ======
===== Steps =====
Generate project:
mvn archetype:generate -DgroupId=com.example -DartifactId=my-console-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Edit pom.xml.
Add compiler source and target versions:
21
21
Specify the ''main'' class:
org.apache.maven.plugins
maven-jar-plugin
true
com.example.App
Build .jar:
mvn clean package
The .jar file is generated inside the target directory. Run it:
java -jar my-console-app-1.0-SNAPSHOT.jar
Output:
Hello World!
===== Add a Dependency =====
org.json
json
20250517
==== Include Dependencies in Jar ====
If you use this, you no longer need the ''maven-jar-plugin'' plugin entry.
maven-assembly-plugin
package
single
jar-with-dependencies
true
com.example.App
===== Makefile =====
default:
@echo 'Targets:'
@echo ' package -- Build the .jar file(s)'
@echo ' list -- Show .jar file(s)'
@echo ' run -- Run the "lite" .jar file (dependencies not included)'
@echo ' run-full -- Run the "full" .jar file (dependencies included)'
package:
mvn clean package
list:
cd target; ls -lh *.jar
run:
cd target; java -jar my-console-app-1.0-SNAPSHOT.jar
run-full:
cd target; java -jar my-console-app-1.0-SNAPSHOT-jar-with-dependencies.jar
===== Complete Updated Pom Example =====
4.0.0
com.example
my-console-app
jar
1.0-SNAPSHOT
my-console-app
http://maven.apache.org
junit
junit
3.8.1
test
org.json
json
20250517
21
21
maven-assembly-plugin
package
single
jar-with-dependencies
true
com.example.App
{{tag>java}}