title: How do I directly execute a jar in linux?
body: <p>I just want to be able to do <code>./whatever.jar</code> instead of <code>java -jar whatever.jar</code>.</p>
  
  <p>I've found a way:</p>
  
  <pre><code>#!/bin/bash
  java -jar $0 $*
  exit
  # jar goes here...
  </code></pre>
  
  <p>but it doesn't work. Java just complains that it's an invalid/corrupt jarfile.</p>
  
  <p>I also tried piping:</p>
  
  <pre><code>#!/bin/bash
  tail -n +4 $0 | java -jar
  exit
  # jar goes here...
  </code></pre>
  
  <p>but this doesn't work.</p>
  
  <p>One way to do it is to somehow split the file into two separate parts (the script part and the jar part), and then execute the jar, but that'd be redundant. You'd might as well make a script that executes the jar and execute that script.</p>
  
  <p>So I need to figure out how to somehow <code>tail</code> it and fake the file.</p>
  
  <p>I thought I could do it using <code>/dev/stdout</code>:</p>
  
  <pre><code>#!/bin/bash
  java -jar /dev/stdout
  tail -n +5 $0
  exit
  # jar goes here...
  </code></pre>
  
  <p>That doesn't work either. It just prints the contents of the jar and java complains that it's invalid. (I figured out later that there's nothing to read in <code>/dev/stdout</code>)</p>
  
  <p>So I need to read from <code>stdout</code> some other way. I really wish I could pipe it though. It would make things SO much easier :)</p>