1

I'm new to Linux and Ubuntu environment.

I'm calling a jar file like this :

java -jar app.jar /somearg /anotherarg

But I find this ugly and I want to call my jar file like :

MyApp /somearg /anotherarg

So I think I have to set a environment variable like MyApp = java -jar app.jar.

But I don't know how can I do it.If anyone can help me I'll be very pleased.Thanks.

dbmitch
  • 5,361
  • 4
  • 24
  • 38
  • 2
    You need an "[alias](http://tldp.org/LDP/abs/html/aliases.html)". P.S. using `/` for options on Unix systems is **very** odd... – Boris the Spider Aug 14 '16 at 17:47
  • Normally a startup shell script is used to prepare the environment and start an application (written in any language except those compiled to native binary code). – Oleg Sklyar Aug 14 '16 at 20:33

1 Answers1

1

Using

java -jar app.jar /somearg /anotherarg

instead of

myapp /somearg /anotherarg

saves you only 2 words, so not that much. Anyway if you run your application frequently it is a good idea to provide an alias. If you are using bash shell (echo $SHELL shows something like /bin/bash) then here's the command you can paste in your terminal:

alias myapp="java -jar /path/to/your/app/app.jar"

After that you can use

myapp /somearg /anotherarg

It is important to provide the whole path to your app.jar file if you run it from different locations. Also if you want that your alias is permament (i.e. it is always after you log in) just add the same line at the end of ~/.bashrc file, using for example:

pico ~/.bashrc

PS. You don't need slash symbol to provide parameters. In unix systems it is more common to use "-" to set argument options.

PSS. Unix systems are case sensitive and it is typical that command line programs are all written in lowercase.

haddr
  • 2,988
  • 1
  • 16
  • 16