I am tired of
javac filename.java
and then
java filename
isn't there a way to make my own command?
mycommand filename.java
And the filename.java
is both compiled and run??
I am tired of
javac filename.java
and then
java filename
isn't there a way to make my own command?
mycommand filename.java
And the filename.java
is both compiled and run??
You can create really small bash script:
Put this to
/usr/local/bin/runjava.sh
, and executeThen you can just type
to compile and run it.
Alternatively, you can put
runjava.sh
(or your own name to it) to~/bin
folder. If that folder do not exist, you can create it with commandmkdir ~/bin
. After opening new terminal, it's in yourPATH
automatically (assuming Ubuntu and bash, without.bashrc
customizations).First method adds it to all users in your system, second one only to you.
So, assuming bash (You are running ubuntu right? ;) ), you can create a function for this...
and then if you have a file called
PureJavaAwesomeness.java
, you could doand that should compile and run the java file.
Edit: And, you might want to put that function definition at the end of your
~/.bashrc
file, so it is loaded every time you open your terminal.Edit2: For some more awesomeness, you can use this function
This will work even when you do
j com/ssk/apps/PackagedClass.java
, assuming the package of thePackagedClass.java
iscom.ssk.apps
. (Not tested, but should work).THIS IS AN OVERKILL FOR WHAT YOU NEED BUT SOMEONE ELSE MIGHT STUMBLE UPON THE QUESTION SEARCHING FOR "HOW TO MAKE OWN COMMANDS ON UBUNTU".
You can use quickly ubuntu-cli-application template to create commands and easily package them as debs or share using ppas.
You'll need some knowledge of python though.
First install Quickly from the Software Center.
Then in the terminal type,
This will create a project directory for you complete with command line handling structure. All you have to do is to edit the files to add your own commands.
Once done, you can share your new commands with friends using
This will create a DEB package ready to be installed on any Ubuntu machine.