Java Apps with the bash Interpreter

This guide explains how to wrap a Java-based app using the "bash" app interpreter. Most apps that run existing Java analyses can be ported to run on the DNAnexus Platform without the need for the Java API bindings. For more complex apps that need to make API calls in-process with Java, see the full Java app tutorial.

To get started, follow the Writing DNAnexus Apps in bash tutorial, which will walk you through using dx-app-wizard to generate a bash app. The wizard will generate some boilerplate for your app, including dx download and dx upload commands to download any file inputs and upload any file outputs that you've declared at this point.

Then make the following changes to the generated app:

Supply your Java program and invoke it: in the main shell script, where it says "Fill in your application code here", invoke your program. Here is an example:

java -jar /opt/myapp/MyApp.jar --input=infile --output=outfile

For this example, you would also copy the .jar file for your app to resources/opt/myapp/MyApp.jar so that Java can find it.

By default, if you define an input called infile and an output called outfile, the app wizard adds boilerplate to your app that downloads the input file to infile in your app's working directory, and expects your app to write its output to outfile in the same directory (from which it will be uploaded back to the platform). If your app follows some other convention for its input or output filenames, then change the filenames in the boilerplate code (highlighted in bold below).

dx download "$infile" -o infile # Your Java invocation goes here # ... outfile=$(dx upload outfile --brief) dx-jobutil-add-output outfile "$outfile" --class=file

Install a Java runtime: add the following to your dxapp.json's execDepends to install OpenJDK's Java 6 runtime before your app begins:

  "runSpec": {
    "execDepends": [{"name": "openjdk-6-jre-headless"}],

If you wish to use Java 7, openjdk-7-jre-headless is also available in the execution environment.

Last edited by Phil Sung, 2013-12-17 18:47:20