Since Java 10 as I recall, we can run Java source files directly from the command line:
bash
$ java Math.java
The JVM compiles and executes the file automatically.
However, in zsh, tab autocompletion with java does not list .java files—just .class, .jar, or other artifacts (perhaps .war and maybe others).
Minimal reproducible example:
Create a simple Java source file:
// Math.java
public class Math {
public static void main(String[] args) {
System.out.println("Hello from Math!");
}
}
Open a zsh shell and try tab-completing after typing:
$ java [ press <TAB> ]
Only Math.class or Math.jar appear. Math.java doesn’t.
Questions:
- Is it possible to configure zsh (or its completion system) so .java files are autocompleted with java?
EDIT:
I tried to the what in his answer. However, no luck. First, I downloaded the updated _java file and I placed it where it was installed, ie.
❯ pacman -Ql zsh |grep java
zsh /usr/share/zsh/functions/Completion/Unix/_java
zsh /usr/share/zsh/functions/Completion/Unix/_java_class
I placed it under /usr/share/zsh/functions/Completion/Unix/_java, replacing the original file. Then I logged out and then logged it. It hasn't fixed the issue. PLease have a look at the following screenshot:
In ~/src I have a few *.java files:
❯ ls *.java
NoNPE.java OpenPortScanner.java
I run oh-my-zsh. To test whether this causes issues, I run zsh in the following way: zsh -f so that no config file was loaded. It turns out that there seems to be autocomplete functionality for *.java files as know I see folders and *.java files being suggested. In other words, oh-my-zsh seems to be the problem. How can I fix that?

zsh -f, you don't get the advanced completion. You still need to run at leastautoload compinit; compinit.echo $fpathsomewhere under your home directory. 2. When you change (as opposed to adding) a completion file, you need to arrange to regenerate the cache, see unix.stackexchange.com/questions/535509/… .