Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java main class autocomplete

If I'm trying to run a java program and I don't know the exact name of the Main class, is there any way to use tab completion to figure it out?

java -cp stackoverflow.jar org.<tab>
stackoverflow serverfault stackexchange

java -cp stackoverflow.jjar org.stackoverflow.<tab>
Main IntegrationTest QuestionAnswerConsole

Something along those lines.

like image 735
volni Avatar asked Dec 17 '25 17:12

volni


2 Answers

Basically you are asking how to configure shell autocompetion to support java. It is possible. Take a look on this discussion: How does bash tab completion work?

I have to say that this is a good idea not only for discovering the main class but also to complete other command line options and a class path. I'd be glad to use such script if you develop it. Good luck.

EDIT

At least on my Ubuntu file less /usr/share/bash-completion/completions/java exists and therefore some completion should work. You are always welcome to improve the script.

like image 169
AlexR Avatar answered Dec 19 '25 11:12

AlexR


The only way to get the Tab Completion that you are talking about is to use a shell that is "Java aware" or a shell script that provides this feature for the java command. git has a similar feature, so I don't think it's completely impossible.

Edit:

According to this question on SU, it is possible to create an autocompletion script for the bash shell. Since the question on SU is slightly different than what you are asking, I don't see a lot of specific details that relate to this question. However, it looks like a good place to start.

like image 20
Code-Apprentice Avatar answered Dec 19 '25 09:12

Code-Apprentice



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!