Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Creating the Distribution Jar

It is assumed in the instructions below that that any reference to hps-distribution-bin.jar jar actually refers to a local copy of the HPS Java distribution from the target dir with an actual version.  

For instance, after building the HPS Java project locally on a recent check of trunk, my distribution jar can be found here.

...

In the commands below, the version, here "3.6-SNAPSHOT", is generally left out for brevity, but when .  When executing commands you need to point to an actual distribution jar you have built or downloaded.

...

Using the -jar switch from the command line will run the main from the class JobManager, which is listened is listed in the manifest inside the jar.

...

Without any arguments it will print the command line options and then exit.

The default main method can be used when you are processing LCIO files using XML steering configurations.

Running a Specified Class's Main

...

Some XML steering files have variables that need to be resolved with command line arguments.

If you get "class not found" errors, then either the path to the distribution jar is not correct.  This error may also occur if the class you have specified doesn't exist or does not have a main method.

A class can only be accessed from the command line if it has a valid main method.

Code Block
languagejava
package org.example;
 
public class MyClass {
    public static void main(String[] args) {
        System.out.println("hello main");
    }
}

To be directly accessible from the command line, a class must have the following features.

  • It must be marked as public or it will not be accessible.
  • It must have a public static method called main (as shown above).
  • The main method has an array of strings as input (with the command line arguments)

Assuming the above class was bundled inside the distribution (it isn't because it is just a dummy example!), it could be run from the command line as follows.

Code Block
languagebash
java -cp ./distribution/target/hps-distribution-bin.jar org.example.MyClass arg1 arg2 [...]

Most classes that implement a command line interface will print out help when run with no options e.g.

Code Block
languagebash
java -cp ./distribution/target/hps-distribution-bin.jar org.hps.evio.Evio2Lcio

If implemented by the author, then -h is usually used equivalently to print out a help menu.

Code Block
languagebash
java -cp ./distribution/target/hps-distribution-bin.jar org.hps.evio.Evio2Lcio -h

Specific command line syntax is not standardized and will depend on what was implemented in that class by the author.

Steering Files

Steering File Location

...