Search code examples
javawindowscmdsublimetext3build-system

ST3 - Build System Supporting packages in java


This is my case: I have a Project Folder in Documents named "JavaProgs2" It has many .java files, 1 Directory for classpaths called "Classes" & 2 Packages (Directories) "myPack1" and "myPack2" which has files "Parent.java" and "Child.java" respectively. "Child.java" imports a method from "Parent.java" My java Build System in ST3 is :

{
    "cmd": ["javac","-d","$folder/Classes", "$file"],
    "working_dir":"$folder",
    "path": "D:/Program Files/Java/jdk1.8.0_91/bin",
    "shell": true,
    "variants": [

        {   
            "cmd": ["start","cmd", "/k", "java", "$file_base_name"],
            "working_dir":"$folder/Classes",
            "shell": true,
            "name": "Run"
        }
    ]
}

I have no problems in compiling any .java file be it in a package or in the Project Folder. But, when running the files I get the "could not find or load..." error. So is there any replacement for "java", "$file_base_name" which will send a command like java <package name>.<classname> when required to CMD from the working_dir ?? Maybe there's something like $folder_name.$file_base_name which i can use in the build system

I prefer not to use an IDE.


EDIT:

I want to edit the RUN variant of my build system for that I need this help: Is there a way to Strip a Path like D:\Users\Horcrux\Documents\JavaProgs2\Classes\myPack1\Parent.class to just myPack1/Parent or similarly D:\Users\Horcrux\Documents\JavaProgs2\Classes\myPack1\blahblah\abc\Test.class to just myPack1/blahblah/abc/Test ???

IN short only the path After the "worikng_dir" till the $file_base_name is sent to CMD from Sublime Text with replacing "\" to "/", where the working_dir is

"D:\Users\Horcrux\Documents\JavaProgs2\Classes\"

EDIT 2: Okay I figured out this much.. it's very close.In the build system I entered this snippet:

${file/(D.+?s2\\\\)||(.java)//g}

Which sends this command to CMD:

java myPack1\test3\_2ArithmeticOperations

Now only thing i cant figure out is how to replace "\" to "/" Can you please try to edit the snippet to perform the replacement also?


Solution

  • Your question is rather unclear, but you can find all of the available build system variables in the official docs. You may also be interested in learning about substitutions using regular expressions - the link is to the snippets page, but substitutions work the same way in build systems.