Skip to content
Advertisement

Sublime 2 Java build

Hi i am using this build system that i found here on so but for some reason it is still not working, the output i get is the javac options i have used this build system.I have used the default one with no luck had a look on-line and couldn’t find much.

{
  "cmd": ["javac", "$file_name","&&","java", "$file_base_name"],
  "working_dir": "${project_path:${folder}}",
  "selector": "source.java",
  "shell": true
}

is there a better build system that i can use??

Advertisement

Answer

You can also try this. It works for me.

{
    "cmd": ["javac '$realpath$file' && java $file_base_name && rm *.class"],
    "selector": "source.java",
    "shell": true,
    "variants": [

        {
            "name": "JavaDoc",
            "cmd": ["mkdir documentation && javadoc -d documentation *.java"]
        },

        {
            "name": "JAR",
            "cmd": ["javac '$realpath$file' && echo "Main-Class: $file_base_name" > Manifest.txt && jar cfm $file_base_name.jar Manifest.txt *.class && rm *.class && java -jar $file_base_name.jar"]
        },


    ]
}

This works for me on Linux and can be downloaded on Github at Java.sublime-build

The interesting thing is that it also compile files to JAR. Remove classes after compilation to make things neater and it also support generating JavaDocs.

The only limitation is that it cannot accept user input or arguments at compile time. You would have to do that manually in the terminal.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement