Integrate Ant builder into Eclipse: Error "Variable references empty selection"

25,851

Solution 1

Obviously, it has problems translating a reference to a variable (${project_path}) inside ... a reference to a variable (${workspace_loc}).

You could try the ${build_project} variable instead

${build_project:/build.xml}

I hope it helps.

Solution 2

You suffered some inconvenience in the Eclipse's UI. The logic dictates you that when you have opened a project, the variables regarding the opened project should be populated. But they're not, because due to a bug or other reason, the code killed them after the focus moved elsewhere.

So as a workaround you can:

  1. Put the full path to the xml file
  2. Just before launching your external tool, click on the project on the left (in Project Explorer view), then press the launch button.

Clicking on the project (folder icon) will populate the variables

By the way, I think ${workspace_loc}${project_path}/build.xml is ok.

Share:
25,851

Related videos on Youtube

Philipp Wendler
Author by

Philipp Wendler

Software developer, Ubuntu user

Updated on July 09, 2022

Comments

  • Philipp Wendler
    Philipp Wendler almost 2 years

    I have some Ant tasks in my Eclipse JDT project that I want to execute before each compilation, so I added an Ant builder to my Eclipse builder config. As the location of the build file, I entered

    ${workspace_loc:${project_path}/build.xml}
    

    I do not want to have any absolute paths, or the project name, here. The Eclipse configuration is part of the repository, and other users check this out with different file-system layouts and possibly different Eclipse project names. For example, I usually have several working copies of the same project in my Eclipse workspace, each of course with a different project name.

    This works most of the time. However, I sometimes get the following error message in a dialog box:

    Errors occurred during the build.
    Errors running builder 'Integrated External Tool Builder' on project 'MyProjectName'.
    Variable references empty selection: ${project_path}
    Variable references empty selection: ${project_path}

    This seems to happen when Eclipse decides to build the project while no resource of the project is selected in the Package Explorer. I can reproduce it by creating a dummy file in the project, deleting the file outside of Eclipse, selecting it in Eclipse and pressing F5. Eclipse will note that the file no longer exists, remove it from the Package Explorer (so nothing is selected anymore) and then build the project, giving the error message.

    While it's not really that important that the Ant tasks are run for every compilation, I do not want to have such an error message box which will confuse users.

    So how can I

    • reference the build.xml file in a different way such that the problem goes away, or
    • fix the problem, or
    • suppress the error dialog for this particular error?

    Any help would be appreciated. I'm using Eclipse 3.7 (Indigo).

  • Philipp Wendler
    Philipp Wendler almost 11 years
    Thanks for your answer. Unfortunately, it does not help me, because (as I said) I cannot use full paths (file is in repository), and this is not about launching a tool manually, but about (automatic) project building, so Eclipse decides when it does this, not me. However, the answer from Efthymis is correct and working, so no need for workarounds.
  • fred271828
    fred271828 about 9 years
    Step #2 here fixed the problem for me. For some reason if the focus is in the editor view then ${project_loc} isn't populated when debugging. Clicking on the project in the Project Explorer view immediately before launching fixed the problem as suggested. Thanks!
  • Thomas Weller
    Thomas Weller almost 9 years
    Any nobody was able to fix this until 2015 :-( I always get this kind of problem when I want to re-run a failed unit test after I made changes to the code.
  • Heri
    Heri over 8 years
    @Thomas: agreed. I use ${project_loc} in a launch configuration as part of a VM command line param. A launch configuration is clearly assigned to an eclipse project. But when another project in the project explorer has focus, the error appears when starting the launch config, and it works when the correct project has the focus. Not really what one would expect