Search code examples
javasublimetext3sublimetextjavac

(Sublime Text 3) bash: javac: command not found


I'm trying to get a working build system for Java on Sublime Text 3, but whenever I try to run anything, i just get bash: javac: command not found.

The strangest thing about this is that I can run the javac command from a terminal, as I have added the line

export JAVA_HOME=/usr/lib/jvm/java-14-openjdk && export PATH=$JAVA_HOME/bin:$PATH

to the .bashrc file in my home directory.

So I have no idea why I can run Java files using javac and java from the terminal, however Sublime Text cannot.

Here is what I have for my build system:

{
   "shell_cmd": "javac \"$file_name\" && java \"$file_base_name\"",
   "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
   "selector": "source.java",
}

I am using Manjaro 20.


Solution

  • I see that you are using Manjaro, which is Arch derivative; instead of setting the JAVA_HOME variable, you should use archlinux-java to set the default JDK version. archlinux-java is part of java-runtime-common package.


    When something is wrong, Sublime will print your current path variable (example). Make sure the paths are set correctly.

    I tried your build system on my Arch machine, and it is working correctly, I also tried setting the JAVA_HOME variable, and it is still working.

    Using Sublime Text 3 Build 3211