relpipe-data/examples-runnable-jars.xml
branchv_0
changeset 294 abbc9bcfbcc4
child 316 d7ae02390fac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relpipe-data/examples-runnable-jars.xml	Mon Feb 03 22:10:07 2020 +0100
@@ -0,0 +1,68 @@
+<stránka
+	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
+	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
+	
+	<nadpis>Finding runnable JARs</nadpis>
+	<perex>look for Java archives with a main class</perex>
+	<m:pořadí-příkladu>03900</m:pořadí-příkladu>
+
+	<text xmlns="http://www.w3.org/1999/xhtml">
+		
+		<p>
+			Java archives (<code>*.jar</code> files) that have set the main class can be started using <code>java -jar program.jar</code> command.
+			Let us find all JARs under a certain directory that are runnable.
+		</p>
+		
+		<m:pre src="examples/runnable-jars.sh" jazyk="bash"/>
+		
+		<p>
+			The script above will print output like this one:
+		</p>
+		
+		<m:pre src="examples/runnable-jars.txt" jazyk="text"/>
+		
+		<p>
+			This pipeline consists of five steps:
+		</p>
+		
+		<ul>
+			<li>
+				<code>findFiles</code>
+				– prepares the list of files separated by <code>\0</code> byte;
+				if we omit the <code>-iname '*.jar'</code>, the result will be the same,
+				just more files will be examinated
+			</li>
+			<li>
+				<code>fetchAttributes</code>
+				– does the heavy work – tries to open each given file as a JAR (same as ZIP format)
+				and looks for the <code>Main-Class</code> field in the <code>META-INF/MANIFEST.MF</code> file (if any);
+				because the <code>jar_info</code> streamlet itself is written in Java, it simply uses existing Java functionality for main class lookup instead of reimplementing it in custom code;
+				thanks to <code>--parallel N</code> option, utilizes N cores of our CPU;
+				we can experiment with the N value and look how the total time decreases
+			</li>
+			<li>
+				<code>filterRunable</code>
+				– uses AWK to skip the records (files) that does not have a main class;
+				in this step we could use also <code>relpipe-tr-sql</code> or <code>relpipe-tr-guile</code> if we prefer SQL or Guile/Scheme to AWK
+			</li>
+			<li>
+				<code>shortenPath</code>
+				– replaces part of the absolute path with the <code>~</code> shortcut
+				(just to make it shorter and hide our username)
+			</li>
+			<li>
+				<code>relpipe-out-tabular</code>
+				– formats the results as a table in the terminal (we could use e.g. <code>relpipe-out-gui</code> to call a GUI viewer or format the results as XML, CSV or other format)
+			</li>
+		</ul>
+		
+		<p>
+			We can omit the <code>-iname '*.jar'</code> and run this pipeline on another directory
+			in order to find all valid JAR and ZIP files regardless their extension.
+			We will get also the number of entries (files and directories) in each archive.
+			In future versions, this streamlet might be extended to optionally provide files from the archive or their list e.g. in form of XML.
+		</p>
+		
+	</text>
+
+</stránka>