relpipe-data/examples-runnable-jars.xml
branchv_0
changeset 294 abbc9bcfbcc4
child 316 d7ae02390fac
equal deleted inserted replaced
293:b862d16a2e9f 294:abbc9bcfbcc4
       
     1 <stránka
       
     2 	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
       
     3 	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
       
     4 	
       
     5 	<nadpis>Finding runnable JARs</nadpis>
       
     6 	<perex>look for Java archives with a main class</perex>
       
     7 	<m:pořadí-příkladu>03900</m:pořadí-příkladu>
       
     8 
       
     9 	<text xmlns="http://www.w3.org/1999/xhtml">
       
    10 		
       
    11 		<p>
       
    12 			Java archives (<code>*.jar</code> files) that have set the main class can be started using <code>java -jar program.jar</code> command.
       
    13 			Let us find all JARs under a certain directory that are runnable.
       
    14 		</p>
       
    15 		
       
    16 		<m:pre src="examples/runnable-jars.sh" jazyk="bash"/>
       
    17 		
       
    18 		<p>
       
    19 			The script above will print output like this one:
       
    20 		</p>
       
    21 		
       
    22 		<m:pre src="examples/runnable-jars.txt" jazyk="text"/>
       
    23 		
       
    24 		<p>
       
    25 			This pipeline consists of five steps:
       
    26 		</p>
       
    27 		
       
    28 		<ul>
       
    29 			<li>
       
    30 				<code>findFiles</code>
       
    31 				– prepares the list of files separated by <code>\0</code> byte;
       
    32 				if we omit the <code>-iname '*.jar'</code>, the result will be the same,
       
    33 				just more files will be examinated
       
    34 			</li>
       
    35 			<li>
       
    36 				<code>fetchAttributes</code>
       
    37 				– does the heavy work – tries to open each given file as a JAR (same as ZIP format)
       
    38 				and looks for the <code>Main-Class</code> field in the <code>META-INF/MANIFEST.MF</code> file (if any);
       
    39 				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;
       
    40 				thanks to <code>--parallel N</code> option, utilizes N cores of our CPU;
       
    41 				we can experiment with the N value and look how the total time decreases
       
    42 			</li>
       
    43 			<li>
       
    44 				<code>filterRunable</code>
       
    45 				– uses AWK to skip the records (files) that does not have a main class;
       
    46 				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
       
    47 			</li>
       
    48 			<li>
       
    49 				<code>shortenPath</code>
       
    50 				– replaces part of the absolute path with the <code>~</code> shortcut
       
    51 				(just to make it shorter and hide our username)
       
    52 			</li>
       
    53 			<li>
       
    54 				<code>relpipe-out-tabular</code>
       
    55 				– 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)
       
    56 			</li>
       
    57 		</ul>
       
    58 		
       
    59 		<p>
       
    60 			We can omit the <code>-iname '*.jar'</code> and run this pipeline on another directory
       
    61 			in order to find all valid JAR and ZIP files regardless their extension.
       
    62 			We will get also the number of entries (files and directories) in each archive.
       
    63 			In future versions, this streamlet might be extended to optionally provide files from the archive or their list e.g. in form of XML.
       
    64 		</p>
       
    65 		
       
    66 	</text>
       
    67 
       
    68 </stránka>