Maven command line usage
-
Download file
mavenTemplate.zipfromhere. -
Extract
mavenTemplate.zipto foldertemplate. -
Optional: Edit
template/pom.xmlreflecting your project needs i.e.<groupId>and related. -
Optional: Import your project in Intellij IDEA.
> mvn --batch-mode -e archetype:generate \
-DgroupId=de.hdm_stuttgart.mi.sd1 -DartifactId=second -Dversion=0.9 \
-DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
[INFO] Scanning for projects...
...
[INFO] BUILD SUCCESS ...See artifact reference.
The MI department provides modified archetypes supporting more current versions of unit testing software. These are being provided by a Maven repository server:
|
Create an empty |
|
|
Use a text editor like nano,
vim, emacs,
IntelliJ,... for creating the following
(presumably new) file
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>development</id>
<repositories>
<repository>
<id>miSupplementaryMavenStuff</id>
<name>Supplementary MI archetypes and artifacts</name>
<!-- The actual »payload« referring to the MI Maven server hosting additional archetypes and artifacts -->
<url>https://maven.mi.hdm-stuttgart.de/nexus/repository/mi-maven</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>development</activeProfile>
</activeProfiles>
</settings>Note
|
> mvn --batch-mode -e archetype:generate \ -DgroupId=de.hdm_stuttgart.mi.sd1 -DartifactId=second -Dversion=0.9 \ -DarchetypeGroupId=de.hdm_stuttgart.mi -DarchetypeArtifactId=mi-maven-archetype-quickstart -DarchetypeVersion=2.5 [INFO] Error stacktraces are turned on. [INFO] Scanning for projects... ... [INFO] BUILD SUCCESS ...
> mvn --batch-mode ❶ -e archetype:generate ❷ \ \ -DarchetypeGroupId=de.hdm_stuttgart.mi \ ❸ -DarchetypeArtifactId=mi-maven-archetype-quickstart \ -DarchetypeVersion=2.5 \ \ -DgroupId=de.hdm_stuttgart.mi.sd1 ❹ \ -DartifactId=second \ -Dversion=0.9
|
During project generation Maven shall work in batch mode not asking for user input. |
|
|
Create a Maven project using an archetype being specified by ❸. |
|
|
Our desired archetype is being addressed by its three »coordinates« on the MI Maven repository server:
|
|
|
Likewise the remaining three parameter uniquely define our own software product's Maven »coordinates«:
|
> tree -a ├── dependency-reduced-pom.xml ├── .gitignore ├── pom.xml ❶ ├── Readme.md └── src ├── main │ ├── java │ │ └── de │ │ └── hdm_stuttgart │ │ └── mi │ │ └── sd1 │ │ ├── App.java ❷ │ │ ├── HighlightSample.java │ │ └── Statistics.java │ └── resources │ └── log4j2.xml └── test └── java └── de └── hdm_stuttgart └── mi └── sd1 └── AppTest.java
No. 117
DNS inflicted groupId / package names clashes
|
Q: |
Regarding the extended explanations of Figure 297, “CLI archetype details ” we consider two different organisations https://hdm-stuttgart.de and https://hdm_stuttgart.de. Following the »coordinate« recommendations both organizations would then choose the common conflicting groupId de.hdm_stuttgart leading to possible Maven artifact clashes. May this conflict actually happen? TipRead about valid DNS domain names. |
|
A: |
The conflict cannot occur since the underscore is being
disallowed in domain names according to the DNS specification. Thus |
> mvn compile [INFO] Scanning for projects... ... [INFO] Building second 0.9 ... [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /ma/goik/second/target/classes [INFO] -------------------------------------------------------- [INFO] BUILD SUCCESS
> tree target/classes target/classes/ ├── de │ └── hdm_stuttgart │ └── mi │ └── sd1 │ ├── App.class │ ├── HighlightSample.class │ └── Statistics.class └── log4j2.xml
> mvn package [INFO] -------------------< de.hdm_stuttgart.mi.sd1:second >------------------- [INFO] Building second 0.9 ... [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running de.hdm_stuttgart.mi.sd1.AppTest [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.253 s -- in de.hdm_stuttgart.mi.sd1.AppTest ... [INFO] Building jar: /home/goik/Downloads/second/target/second-0.9.jar ... [INFO] BUILD SUCCESS
> java -jar target/second-0.9.jar
Hi there, let's have
fun learning Java!
2026-01-11 07:40:33,903 INFO [main] sd1.App (App.java:27) - The following two statements will log to file A1.log, ...
2026-01-11 07:40:33,905 DEBUG [main] sd1.App (App.java:28) - You may configure 'src/main/resources/log4j2.xml'
2026-01-11 07:40:33,905 DEBUG [main] sd1.App (App.java:29) - for adapting both console and 'A1.log' file outputNote
Executing this requires defining
App.class as main entry point in our
project's pom.xml file:
...
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.App</Main-Class>
<Multi-Release>true</Multi-Release>
</manifestEntries>
...Remark: This will execute App.class being
contained in second-0.9.jar.
No. 118
Details on execution
|
Q: |
In Figure 302, “Executing Java™ archive
java -jar target/second-0.9.jar How does this actually work? There might be multiple
executable classes containing TipHave a closer look on your project's
|
|
A: |
Our <project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
...
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.App</Main-Class>
</manifestEntries>
...
</project>The Maven > cat META-INF/MANIFEST.MF Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.5.2 Built-By: goik Build-Jdk: 10.0.2 Main-Class: de.hdm_stuttgart.mi.sd1.App This allows the Java™ runtime to choose the class to be executed. |
> mvn javadoc:javadoc [INFO] Scanning for projects... ... Generating /ma/goik/second/target/site/apidocs/allclasses-noframe.html... Generating /ma/goik/second/target/site/apidocs/index.html... Generating /ma/goik/second/target/site/apidocs/overview-summary.html... Generating /ma/goik/second/target/site/apidocs/help-doc.html...
See e.g. class String documentation.
> mvn clean ... [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ second --- [INFO] Deleting /ma/goik/second/target [INFO] ------------------------------------------------------------------------ [
