Maven command line usage
-
Download file
mavenTemplate.zip
fromhere
. -
Extract
mavenTemplate.zip
to foldertemplate
. -
Optional: Edit
template/pom.xml
reflecting 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
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.3
[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.3 \ \ -DgroupId=de.hdm_stuttgart.mi.sd1 ❹ \ -DartifactId=first \ -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 we do have three parameters uniquely defining our own software product's Maven identity:
|
> cd first # Enter project directory > find . -type f # Search recursively for files ./pom.xml ❶ ./src/main/java/de/hdm_stuttgart/mi/sd1/HighlightSample.java ./src/main/java/de/hdm_stuttgart/mi/sd1/Statistics.java ./src/main/java/de/hdm_stuttgart/mi/sd1/App.java ❷ ./src/main/resources/log4j2.xml ./src/test/java/de/hdm_stuttgart/mi/sd1/AppTest.java ./Readme.md
No. 111
DNS inflicted groupId / package names clashes
Q: |
Regarding the extended explanations of Figure 282, “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 first 0.9 ... [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /ma/goik/first/target/classes [INFO] -------------------------------------------------------- [INFO] BUILD SUCCESS
> find target/classes -type f
./target/classes/de/hdm_stuttgart/mi/sd1/App.class
...
> cd target/classes ❶ > java de.hdm_stuttgart.mi.sd1.App ❷ Hi there, let's have fun learning Java! ❸
Change to base directory containing compiled Java™ classes. |
|
Application execution. Note: Our |
|
The expected output result. NoteExecuting this particular class requires a configuration
in our project's
|
> mvn package ... T E S T S ... Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 ... [INFO] Building jar: /ma/goik/first/target/first-0.9.jar ... [INFO] Replacing /ma/goik/first/target/first-0.9.jar with /ma/goik/first/target/first-0.9-shaded.jar ... [INFO] BUILD SUCCESS
java -jar target/first-0.9.jar
Hi there, let's have
fun learning Java!
Remark: This will execute HelloWorld.class
being contained in first-0.9.jar
.
No. 112
Details on execution
Q: |
In Figure 288, “Executing Java™ archive
java -jar target/first-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
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/First/target/site/apidocs/allclasses-noframe.html... Generating /ma/goik/First/target/site/apidocs/index.html... Generating /ma/goik/First/target/site/apidocs/overview-summary.html... Generating /ma/goik/First/target/site/apidocs/help-doc.html...
See e.g. class String documentation.
> mvn clean
...
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ first ---
[INFO] Deleting /ma/goik/first/target
[INFO] ------------------------------------------------------------------------
[