java - How to install JCommander and use it in my program? -
i doing 1 project , want use jcommander parsing command line input. don't know how add machine , use it.
here github page jcommander. how can add machine after downloading zip file of code?
i not using ide (using sublime text , command line).
i ran same question. here worked me.
download jcommander jar file http://mvnrepository.com/artifact/com.beust/jcommander/latest , follow link "artifact" on table on page. dowloaded file named jcommander-x.xx.jar.
after download, working file @ path myjavafiles/example.java, create directory myjavafiles/lib , put file there.
create minifest.txt file
so have structure
myjavafiles ├── example.java ├── lib │ └── jcommander-x.xx.jar └── manifest.txt
5 can try sample java file 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 , putting can go 2 paths.
6.a generate class files using command javac -cp lib/jcommanderxx.xx.jar example.java
then run program class file directly using java -cp lib/*:. example -l 4 --pattern 5
or if want create self standing jar file...
6.b create manifest.txt file , add classpath , lib paths there class-path: lib/jcommander-x.xx.jar main-class: example
after can compile using javac -cp lib/jcommander-x.xx.jar example.java
and run java -cp lib/*:. example -l 4 --pattern 5
all of ^^ doable via command line without need introduce gradle or maven builds, if you're looking simple way work @ command line should work other libraries too.
Comments
Post a Comment