Sublime Forum

Setting the PATH variable to current project directory

#1

Hello;
I am trying to make a simple build-system for Spring boot (maven) project.
as you know spring starter gives you maven bundled with each spring project you make.
the maven executable is mvnw and is located at the root of project dir.
so I am trying to add the current project to the PATH but it is not expanding.
this is the gist of what I am doing (which is not working).

{
   "shell_cmd": "mvnw spring-boot:run",
	"env": {
		"PATH": "$PATH:$folder"

	},
	"working_dir": "${project_path}", 
}


and it is complaining that mvnw could not be found.
I tried $project_path in env key instead of $folder with no luck.
PS: @OdatNurd I watched you videos. you are awesome. but obviously I am doing thing wrong!
Thanks I advance.

0 Likes

#2

Builds only expand out variables in cmd, shell_cmd and working_dir, so you can’t use variables inside of env the way you’re trying to do here.

That said, if mvnw is in the root of your project:

{
    "shell_cmd": "./mvnw spring-boot:run",
    "working_dir": "${project_path}", 
}

would set the current working directory to the root of your project, and then the shell can execute mvnw from there via a relative path.

If you don’t use sublime-project files, or you do but you don’t store them inside of the root of your project, then use ${folder} instead of ${project_path} here, and make sure that your project folder is the first one listed in the sidebar.

1 Like