If you want an alias for executing a specific class (with specific parameters) add the following to your bash profile file (something like .bash or .profile in your home directory):
alias aliasname="java classname param1 param2"
This would run the class indicated by classname with the parameters specified when you type aliasname in your command line.
However, if you want an alias that can take any class (and any parameter) add the following the your bash profile:
function functionname() { java $@ }
Which is like renaming the java command to functionname without any added benefits.
Note that you would have to execute the following command:
source "filepath_to_your_profile_path"
or restart your terminal for this to take effect.
Cross-posted on StackOverflow: http://stackoverflow.com/questions/32775019/how-to-create-an-alias-for-standard-java-execution-command
– John1024 – 2015-09-25T05:16:05.753Are you trying to be able to just run a Java class without specifying "java" at all, as in load
myclass.class
into the Java runtime just by typing./myclass
? I don't know a way to do that. If you simply want to be able to add parameters to (or make an alternate name for) thejava
command, you can simply usealias
like for any other command. – CBHacking – 2015-09-25T05:41:21.567