16

I have a run configuration in my eclipse. In my project we have two branches : DEV and STABLE. I would like to create one run configuration for building my project whatever branch it is on.

For now, when I set Base directory with one of those two variables : ${project_path}, ${build_project}, I face this error :

Base directory doesn't exist or can't be read.

This works : ${workspace_loc:/my-project-dev-branch} but is tied to a particular branch. I must duplicate this configuration for building the stable branch.

  • So, how can I view the actual content of ${project_path}, ${build_project} ?
  • Or which variable should I use to get this result : ${workspace_loc:/${eclipse_variable_with_project_name}} ?
Stephan
  • 41,764
  • 65
  • 238
  • 329

4 Answers4

19

I'm not sure I follow how your branches are represented within the workspace, but

  • ${project_path} represents a path relative to your workspace
  • ${build_project} will only be set during an actual build (not during an execution of your program)

Based on your description you want to be using ${project_loc} instead.

Nota: The project MUST be selected in the perspective project before launching the run configuration. Otherwise, you will get a message like in the screenshot below :

picture of Alert box popup with the text 'Launching MY RUN CONFIGURATION' has encountered a problem.  Variable references empty selection: ${project_loc}'

randal4
  • 590
  • 4
  • 16
Perception
  • 79,279
  • 19
  • 185
  • 195
  • The branches are located in separate projects. I have tried `${project_loc}/${build_project}` with no success. – Stephan Apr 02 '13 at 11:47
  • 1
    I also use `$project_loc` for similar run configuration. With one notice: such configurations can be started only if appropriate project is selected in Navigator or Package Explorer views. In other words: first - select project, then run the configuration. – DRCB Apr 02 '13 at 11:47
  • @Stephan - use just `$project_loc`, that will give you the full location of the project containing a resource that you are executing. – Perception Apr 02 '13 at 11:48
  • @DRCB `${project_loc}`, I sitll get the same error. This doesn't work either : `${workspace_loc:/${eclipse_variable_with_project_name}}`. – Stephan Apr 02 '13 at 11:49
  • @Perception $project_loc still no success :\ I forget to mention that the Run configuratio is a Maven Build (from m2e plugin). – Stephan Apr 02 '13 at 11:50
  • @Stephan - thats a pretty important detail! You should probably be setting this information up in your POM then. Have you tried using the ${project.dir} property? – Perception Apr 02 '13 at 11:54
  • @Perception ${project.dir} no luck :\ It's a multi module project. If I change the pom.xml containning pom, what should I add ? – Stephan Apr 02 '13 at 11:58
  • @Stephan Here is a screenshot of my working configuration (for Maven). It works only if I select a project in Project Explorer before running this configuration: https://dl.dropbox.com/u/6808560/stackoverflow/project_loc.png – DRCB Apr 02 '13 at 11:58
  • @Stephan - please join me in [chat](http://chat.stackoverflow.com/rooms/27401/how-to-create-a-generic-run-configuration-with-eclipse). – Perception Apr 02 '13 at 12:04
  • @Perception Sorry, chat is blocked where I am :\ – Stephan Apr 02 '13 at 15:27
3

As you are already creating a String Substitution variable, through Run Debug->String Substitution in Eclipse Preferences, to deal with separate paths, you could either:

  1. Create a variable, e.g. branch_loc, with a value of ${workspace_loc:/my-project-dev-branch}
  2. If the paths only differ slightly, e.g. by branch name, then you could create a variable branch with a value, e.g. dev, and then create branch_loc with ${workspace_loc}\${branch}

Then use ${branch_loc} for you Maven base directory.

It would be better to have all branches use the same path, which git and mercurial allow you to do. Then you could use ${project_loc} for your Maven base directory. For project_loc if you specify the project name of your project, e.g. ${project_loc:MY_PROJECT_NAME}, then it doesn't require you to select the project in order to work.

If you right click on the project and then select Properties, you can see what ${project_path} will resolve to by looking at path and what ${project_loc} will resolve to by looking at location.

WhiteKnight
  • 4,938
  • 5
  • 37
  • 41
1

First of all, if you are using git as version control system: Do not checkout the project twice, but just switch between branches in a single project. Git was designed for that and can do that in seconds. That way your problem would vanish completely.

If that is not an option, maybe putting the run configuration under version control itself would be an alternative. Set the Shared file option as shown with the first highlight: enter image description here

Then you can run the run configuration by selecting it in the respective project (as that is really a file there) and launch it via context menu. However, I've never tried this with the same launch configuration checked out twice.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
1

You can set the base directory in below mentioned way:

${project_loc:${project_name}}

You can find the above variables from the variables option.

Also you can set your mvn command in goals as example below:

clean install -PautoInstallPackage -Padobe-public -DskipTests
Roohollah Etemadi
  • 1,243
  • 1
  • 6
  • 18
  • With this solution, is it still required to first select the project in its perspective before launching the run configuration? – Stephan Jul 17 '20 at 21:48