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

Completing the exercise

parent d45e8306
No related branches found
No related tags found
No related merge requests found
......@@ -408,15 +408,75 @@ inputSecond.txt</programlisting>
./Sda1/Jdom/Html2Html/src/main/resources/imageExample.html</programlisting>
<tip>
<para/>
<orderedlist>
<listitem>
<para/>
<para>Read about reading from files by using instances of
<classname
xlink:href="http://www.tutorialspoint.com/java/io/bufferedreader_readline.htm">java.io.BufferedReader</classname>.</para>
</listitem>
<listitem>
<para>Reading from standard input may be achieved by:</para>
<programlisting language="java">final BufferedReader source = new BufferedReader(new InputStreamReader(System.in));
...</programlisting>
</listitem>
<listitem>
<para/>
<para>You may create an executable jar archive using Maven.
Starting from the <code>mi-mavem-archetype-quickstart</code> your
<filename>pom.xml</filename> already contains a blueprint. Just
insert your class containing the entry
<methodname>main(...)</methodname> method (i.e.
<classname>de.hdm_stuttgart.mi.sd1.grep.Grep</classname> in the
current example) accordingly:</para>
<programlisting language="xml">&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
&lt;version&gt;2.4.1&lt;/version&gt;
&lt;configuration&gt;
&lt;transformers&gt;
&lt;transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
&lt;manifestEntries&gt;
&lt;Main-Class&gt;<emphasis role="bold">de.hdm_stuttgart.mi.sd1.grep.Grep</emphasis>&lt;/Main-Class&gt;
&lt;/manifestEntries&gt;
&lt;/transformer&gt;
&lt;/transformers&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;shade&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</programlisting>
<para>Running <command>mvn</command> <option>install</option> will
create an executable jar file
<filename>~/.m2/repository/de/hdm-stuttgart/mi/sd1/grep/0.9/grep-0.9.jar</filename>
with <quote>~</quote> denoting your home directory. You may then
create a simple shell wrapper script <filename>mygrep</filename>
(don't forget to supply execute permission) hiding the
<command>java</command> execution stuff:</para>
<programlisting language="none">#!/bin/sh
# A simple wrapper hiding java execution stuff.
# Do not forget to make this file executable by issuing "chmod ugo+x mygrep"
java -jar ~/.m2/repository/de/hdm-stuttgart/mi/sd1/grep/0.9/grep-0.9.jar $*
#end</programlisting>
<para>You my now simply invoke your application. The following
example reads from standard input by virtue of a pipe:</para>
<programlisting language="none">&gt; cat Testdata/input.txt | ./bin/mygrep red
The red cross acts worldwide</programlisting>
</listitem>
</orderedlist>
</tip>
......
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