I would like to use use java to write a tool to use under linux so that I can call it like I call "ls". What do I need to do? I planed to:
write a java with main function take my arguments, do the job. How do I return results? Java main cannot return string.
Where is the best place to add my jar to in the system? /user/bin?
how can I call it with minimum typing? I don't want to type java jar XXXXXX com.mynamespace.myfunction ...... How can i just call it by using a simple name like "ls"?
Thanks a lot
You can create a bash file /usr/bin/custom_program pointing to your jar:
#!/usr/bin/bash
java -jar /path/to/your/java.jar # add any custom command line switches here
Don't forget to mark it as executable with sudo chmod u+x /usr/bin/custom_program.
Your output would be given as System.out.println() calls in your program -- no need to return String from main.
Then, you can call your java program with custom_program with the help of the bash script above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With