Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java command-line launchers

I am working on a .jar file library to implement a bunch of helper classes to interface a PC to a piece of external hardware. I'll also add some simple applications, either command-line or GUI, to handle common tasks using the library.

My question is, is there a recommended way to simplify the command-line instantiation of a JVM in a certain specific way?

e.g. instead of requiring a user to type a cryptic error-prone command like:

java -cp TurboBlenderLib.jar -jar TurboBlenderApp.jar -DFoo=Bar arg1 arg2

instead I do

TurboBlenderApp arg1 arg2

?

I suppose I could use shell scripts (incl. win32 Batch Files... gacckkk), it's just that I'm not good at those + I was wondering if there was a more straightforward platform-independent way of running a Java app from the commandline.

like image 831
Jason S Avatar asked Sep 20 '26 09:09

Jason S


2 Answers

  1. When you use -jar, then-cp (and the CLASSPATH variable) will be ignored
  2. Just provide a executable jar. "java -jar TheApp <whateverargumentsyouwant>" shouldn't be too hard (you can have a Class-Path attribute in your jar files manifest, however).
  3. if it is too hard write a GUI
  4. or provide those shell scripts/batch files. Writing those isn't too hard either.
like image 110
Joachim Sauer Avatar answered Sep 23 '26 01:09

Joachim Sauer


If you just want to simplify local execution, use a batch file or even just create a custom shortcut. If you want to create a launcher and package the executable jar and required libs for deployment, use something like Launch4j.

like image 38
Christoph Avatar answered Sep 23 '26 01:09

Christoph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!