I just ran into the same question. Here is what worked for me.
Download jcommander jar file from http://mvnrepository.com/artifact/com.beust/jcommander/latest , follow the link for "Artifact" on the table on that page. The dowloaded file is named jcommander-X.XX.jar.
After download, say you are working with a file at path myJavaFiles/Example.java, create a directory myJavaFiles/lib and put the file there.
Create a minifest.txt file
So now you have the structure
myJavaFiles
├── Example.java
├── lib
│ └── jcommander-X.XX.jar
└── manifest.txt
5 You can try this for a sample java file as Example.java
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
class Example {
@Parameter(names={"--length", "-l"})
int length;
@Parameter(names={"--pattern", "-p"})
int pattern;
public static void main(String ... args) {
Example ex = new Example();
new JCommander();
ex.run();
}
public void run() {
System.out.printf("%d %d", length, pattern);
}
}
6 And now putting it all together you can go two paths.
6.a Generate class files using this command javac -cp lib/jcommanderXX.XX.jar Example.java
Then run your program from the class file directly using java -cp lib/*:. Example -l 4 --pattern 5
OR if you want to create a self standing jar file...
6.b create a manifest.txt file and add classpath and lib paths there
Class-Path: lib/jcommander-X.XX.jar
Main-Class: Example
After which you can compile using this javac -cp lib/jcommander-X.XX.jar Example.java
And finally run it with java -cp lib/*:. Example -l 4 --pattern 5
All of this ^^ is doable via the command line without the need to introduce gradle or maven builds, if you're just looking for simple way to work at command line this should work with other libraries too.