Search code examples
javalinuxsublimetext3

How can I make Sublime compile files to a specific directory?


My teacher has given us a script he's written himself for us to use to compile Java. I have organized the folders a specific way (different from our teacher's) because I like my own way of organising things.

My folder structure:

prg/
├─ EasyGraphics.java
├─ class/
│  ├─ lab/
│     ├─ lesson/
│        ├─ GraphicsLesson.java
├─ libraries/
   ├─ eg/

The script he gave us:

  {
    "cmd": ["javac \"-Xlint:none\" \"-cp\" \".:..\" \"-encoding\" \"utf8\" \"$file_name\" "],   
    "shell": "true",
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",   
    "selector": "source.java", 
    "variants":
    [
      {
        "name": "Run",
        "cmd": ["java \"-cp\" \".:..\" \"$file_base_name\" "],
        "shell": "true"
      }
    ]
  }  

The script gave me trouble for when I put EasyGraphics in a different folder, so I edited it to this:

"cmd": ["javac \"-Xlint:none\" \"-cp\" \"./../../../.\" \"-encoding\" \"utf8\"
"cmd": ["java \"-cp\" \"./../../../.\" \"$file_base_name\" "]

When I compile GraphicsLesson.java it creates a large amount of files in the prg dir but I'd like to have them created in /libraries/eg - how can I achieve this?

So far I've tried:

"cmd": ["javac \"-Xlint:none\" \"-cp\" \"./../../../.:libraries/eg\" \"-encoding\" \"utf8\"
"cmd": ["javac \"-Xlint:none\" \"-cp\" \"./../../../.:/libraries/eg\" \"-encoding\" \"utf8\"
"cmd": ["javac \"-Xlint:none\" \"-cp\" \"./../../../.\/libraries/eg\" \"-encoding\" \"utf8\"

And more, but nothing seems to work.

Any help is greatly appreciated. Thanks.


Solution

  • Ok, so I managed to figure out how to extract it to a single sub-dir but not to sub-dirs in sub-dirs:

        "cmd": ["javac \"-Xlint:none\" \"-cp\" \".:../../.././dir:../dir:../../dir\" \"-encoding\" \"utf8\" \"$file_name\" "],
        "shell": "true",
        "file_regex": "^(...*?):([0-9]*):?([0-9]*)",   
        "selector": "source.java", 
        "variants":
        [
          {
            "name": "Run",
            "cmd": ["java -cp .:../../.././dir:../dir:../../dir $file_base_name "],
            "shell": "true"
          }
        ]
      }