Skip to content
Snippets Groups Projects
Commit 12f01ab0 authored by Goik Martin's avatar Goik Martin
Browse files

New mhelloWorld maven archetype

parent e4afb622
No related branches found
No related tags found
No related merge requests found
Showing
with 294 additions and 106 deletions
......@@ -2293,10 +2293,9 @@ nano ~/.m2/settings.xml <co linkends="sd1_fig_mavenMiRepo-2"
<figure xml:id="sd1_fig_mavenMiRepoCliTest">
<title><xref linkend="glo_CLI"/> archetype test</title>
<screen>mvn --batch-mode -e archetype:generate \
-DgroupId=de.hdm_stuttgart.mi.sd1 \
-DartifactId=first -Dversion=0.9 -DarchetypeGroupId=de.hdm_stuttgart.mi \
-DarchetypeArtifactId=<emphasis role="red">mi-maven-archetype-quickstart</emphasis> -DarchetypeVersion=1.2
<screen>mvn --batch-mode -e archetype:generate -DgroupId=de.hdm_stuttgart.mi.sd1 \
-DartifactId=second -Dversion=0.9 -DarchetypeGroupId=de.hdm_stuttgart.mi \
-DarchetypeArtifactId=<emphasis role="red">mi-maven-archetype-helloworld</emphasis> -DarchetypeVersion=1.2
[INFO] Scanning for projects...
...
......@@ -2346,7 +2345,7 @@ nano ~/.m2/settings.xml <co linkends="sd1_fig_mavenMiRepo-2"
<property>archetypeVersion</property> uniquely identify an
archetype worldwide.</para>
<para><package>mi-maven-archetype-quickstart</package> denotes one
<para><package>mi-maven-archetype-helloworld</package> denotes one
of several <link
xlink:href="https://maven.mi.hdm-stuttgart.de/nexus/#browse/browse:mi-maven">available
archetypes</link>.</para>
......@@ -2371,14 +2370,9 @@ nano ~/.m2/settings.xml <co linkends="sd1_fig_mavenMiRepo-2"
&gt; find . -type f <emphasis role="red"># Search recursively for files</emphasis>
./.gitignore <co linkends="sd1_fig_mavenFirstPrjLayout-1"
xml:id="sd1_fig_mavenFirstPrjLayout-1-co"/>
./src/test/java/de/hdm_stuttgart/mi/sd1/AppTest.java <co
linkends="sd1_fig_mavenFirstPrjLayout-2"
xml:id="sd1_fig_mavenFirstPrjLayout-2-co"/>
./src/main/java/de/hdm_stuttgart/mi/sd1/App.java <co
linkends="sd1_fig_mavenFirstPrjLayout-3"
xml:id="sd1_fig_mavenFirstPrjLayout-3-co"/>
./src/main/resources/log4j2.xml <co linkends="sd1_fig_mavenFirstPrjLayout-4"
xml:id="sd1_fig_mavenFirstPrjLayout-4-co"/>
./pom.xml <co linkends="sd1_fig_mavenFirstPrjLayout-5"
xml:id="sd1_fig_mavenFirstPrjLayout-5-co"/></screen>
......@@ -2390,25 +2384,12 @@ nano ~/.m2/settings.xml <co linkends="sd1_fig_mavenMiRepo-2"
control.</para>
</callout>
<callout arearefs="sd1_fig_mavenFirstPrjLayout-2-co"
xml:id="sd1_fig_mavenFirstPrjLayout-2">
<para><xref linkend="glo_Java"/> source file defining automated
<xref linkend="glo_Junit"/> tests.</para>
</callout>
<callout arearefs="sd1_fig_mavenFirstPrjLayout-3-co"
xml:id="sd1_fig_mavenFirstPrjLayout-3">
<para><xref linkend="glo_Java"/> source file containing an
executable <methodname>main()</methodname> class.</para>
</callout>
<callout arearefs="sd1_fig_mavenFirstPrjLayout-4-co"
xml:id="sd1_fig_mavenFirstPrjLayout-4">
<para>Configuring <link
xlink:href="https://logging.apache.org/log4j">Apache Log4j logging
framework</link>.</para>
</callout>
<callout arearefs="sd1_fig_mavenFirstPrjLayout-5-co"
xml:id="sd1_fig_mavenFirstPrjLayout-5">
<para>The <emphasis role="red">P</emphasis>roject <emphasis
......@@ -2442,79 +2423,37 @@ nano ~/.m2/settings.xml <co linkends="sd1_fig_mavenMiRepo-2"
./target/classes/<emphasis role="red">de/hdm_stuttgart/mi/sd1/App.class</emphasis></screen>
</figure>
<qandaset defaultlabel="qanda" xml:id="sd1_qanda_WhyDoesExecFail">
<title>What about execution?</title>
<qandadiv>
<qandaentry>
<question>
<para>Follow the previous steps creating your own
<package>mi-maven-archetype-quickstart</package> based project
and execute <command>mvn</command> <option>compile</option>.
Then try to execute the generated bytecode file:</para>
<screen>cd target/classes
java de.hdm_stuttgart.mi.sd1.App</screen>
<para>What happens? Explain this result.</para>
</question>
<answer>
<para>Execution fails:</para>
<screen>&gt; java de.hdm_stuttgart.mi.sd1.App
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/logging/log4j/LogManager
at de.hdm_stuttgart.mi.sd1.App.&lt;clinit&gt;(App.java:14)
Caused by:
java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
...</screen>
<para>As we shall see additional libraries being defined in our
project's <filename>pom.xml</filename> file are missing:</para>
<programlisting language="xml">&lt;project xmlns="http://maven.apache.org/POM/4.0.0" ...&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
...
&lt;dependency&gt;
&lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
&lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
&lt;version&gt;2.11.0&lt;/version&gt;
&lt;/dependency&gt;
...
&lt;/project&gt;</programlisting>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
<figure xml:id="sd1_fig_mavenTest">
<title><xref linkend="glo_Maven"/> test</title>
<screen>&gt; mvn test
...
[INFO] Changes detected - recompiling the module!
[INFO] <emphasis role="red">Compiling 1 source file</emphasis> to /ma/goik/first/<emphasis
role="red">target/test-classes</emphasis>
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running de.hdm_stuttgart.mi.sd1.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.567 sec
...</screen>
</figure>
<figure xml:id="sd1_fig_mavenExecute">
<title>Execution</title>
<screen>&gt; cd target/classes <co linkends="sd1_fig_mavenExecute-1"
xml:id="sd1_fig_mavenExecute-1-co"/>
&gt; java de.hdm_stuttgart.mi.sd1.App <co linkends="sd1_fig_mavenExecute-2"
xml:id="sd1_fig_mavenExecute-2-co"/>
Hello World! <co linkends="sd1_fig_mavenExecute-3"
xml:id="sd1_fig_mavenExecute-3-co"/></screen>
<calloutlist>
<callout arearefs="sd1_fig_mavenExecute-1-co"
xml:id="sd1_fig_mavenExecute-1">
<para>Change to base directory containing compiled <xref
linkend="glo_Java"/> classes.</para>
</callout>
<figure xml:id="sd1_fig_mavenTestFileView">
<title>Test file view</title>
<callout arearefs="sd1_fig_mavenExecute-2-co"
xml:id="sd1_fig_mavenExecute-2">
<para>Execute the application. Note that our
<classname>App</classname> class name is being prefixed by the
package name <package>de.hdm_stuttgart.mi.sd1</package> defined by
parameter <emphasis role="red">groupId</emphasis> in <xref
linkend="sd1_fig_mavenMiRepoCliDetails"/>.</para>
</callout>
<screen>&gt; find . -type f
...
./target/test-classes/de/hdm_stuttgart/mi/sd1/AppTest.class
...
./target/surefire-reports/de.hdm_stuttgart.mi.sd1.AppTest.txt
./target/surefire-reports/TEST-de.hdm_stuttgart.mi.sd1.AppTest.xml
./target/classes/de/hdm_stuttgart/mi/sd1/App.class</screen>
<callout arearefs="sd1_fig_mavenExecute-3-co"
xml:id="sd1_fig_mavenExecute-3">
<para>The expected output result.</para>
</callout>
</calloutlist>
</figure>
<figure xml:id="sd1_fig_mavenPackage">
......@@ -2538,11 +2477,7 @@ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
<title>Executing <filename>first-0.9.jar</filename></title>
<screen>java -jar <emphasis role="red">target/first-0.9.jar</emphasis>
Hello World!
2018-10-03 17:49:00,700 DEBUG [main] sd1.App (App.java:24) -
You may configure 'src/main/resources/log4j2.xml'
2018-10-03 17:49:00,704 DEBUG [main] sd1.App (App.java:25) -
for adapting both console and 'A1.log' file output</screen>
Hello World!</screen>
</figure>
<qandaset defaultlabel="qanda" xml:id="sd1_qanda_executionMechanism">
......@@ -2746,12 +2681,12 @@ Generating /ma/goik/First/target/site/apidocs/help-doc.html...
<itemizedlist>
<listitem>
<para><property>archetypeArtifactId</property>:
<option>mi-maven-archetype-quickstart</option></para>
<option>mi-maven-archetype-helloworld</option></para>
</listitem>
<listitem>
<para><property>archetypeVersion</property>:
<option>1.1</option></para>
<option>1.2</option></para>
</listitem>
</itemizedlist>
......
......@@ -17,7 +17,7 @@ $(M2DIR)/%/maven-metadata-local.xml:%/pom.xml
#</servers>
#
deploy: $(foreach aType, $(ARCHETYPES), $(M2DIR)/$(aType)/maven-metadata-local.xml) archetype-catalog.xml
rsync -av --delete -e ssh index.html archetype-catalog.xml mvndeploy@maven.mi.hdm-stuttgart.de:/var/www/html/maven
rsync -av --delete -e ssh index.html archetype-catalog.xml freedocs@maven.mi.hdm-stuttgart.de:/var/www/html/maven
clean:
rm -rf $(foreach aType, $(ARCHETYPES), $(M2DIR)/$(aType))
......
/target/
/.settings/
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
Final success via http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html
Create Project from local repository using:
mvn --batch-mode -e archetype:generate -DgroupId=de.hdm_stuttgart.mi.sd1 \
-DartifactId=first -Dversion=0.9 -DarchetypeGroupId=de.hdm_stuttgart.mi \
-DarchetypeArtifactId=mi-maven-archetype-helloworld -DarchetypeVersion=1.2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hdm_stuttgart.mi</groupId>
<artifactId>mi-maven-archetype-helloworld</artifactId>
<version>1.2</version>
<packaging>maven-archetype</packaging>
<name>MI Maven archetype helloworld</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url>
<description>
This archetype provides a minimal Java project still allowing for executable jar generation.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository>
<id>mi-nexus</id>
<url>https://maven.mi.hdm-stuttgart.de/nexus/repository/mi-maven</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.0.1</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<!-- Required so that .gitignore gets included in archetypes; see https://issues.apache.org/jira/browse/MRESOURCES-190 -->
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="def"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="false" packaged="false" encoding="UTF-8">
<directory/>
<includes>
<include>.gitignore</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
/target/
/.settings/
.classpath
.project
dependency-reduced-pom.xml
*.log
Java project template
====================
General:
--------
This is a very minimal »HelloWorld« style Java project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>jar</packaging>
<name>${artifactId}</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1SectToolsOfTheTrade2.html</url>
<description>Basic Java project.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<linksource>true</linksource>
<additionalOptions>
<additionalOption>-html5</additionalOption>
</additionalOptions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${package}.App</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
</project>
package $package;
/**
* A simple HelloWorld style application.
*/
public class App {
/**
* Your application's main entry point.
*
* @param args Yet unused
*/
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
......@@ -2,7 +2,6 @@ Final success via http://maven.apache.org/archetype/maven-archetype-plugin/examp
Create Project from local repository using:
mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=de.hdm-stuttgart.mi \
-DarchetypeArtifactId=mi-maven-archetype-quickstart -DarchetypeVersion=1.1 \
-DgroupId=de.mi.hdm_stuttgart -DartifactId=hello -DinteractiveMode=false
mvn --batch-mode -e archetype:generate -DgroupId=de.hdm_stuttgart.mi.sd1 \
-DartifactId=first -Dversion=0.9 -DarchetypeGroupId=de.hdm_stuttgart.mi \
-DarchetypeArtifactId=mi-maven-archetype-quickstart -DarchetypeVersion=1.2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment