How to set Ant properties based on variables in Eclipse?

后端 未结 5 1924
我在风中等你
我在风中等你 2021-02-13 23:00

I have a common problem and there are probably countless ways to solve it. I\'m looking for an elegant, simple solution to this typical scenario:

I have a project in Ec

相关标签:
5条回答
  • 2021-02-13 23:41

    See Window -> Preferences -> Ant -> Runtime -> Properties to define custom ant properties that should be available to any ant script invoked from Eclipse. The simply set the same property manually when invoking script from command-line.

    Your build.properties file can exist wherever you like. Use normal Ant facilities to import it into your script.

    0 讨论(0)
  • 2021-02-13 23:45

    You can set eclipse relative properties for your ANT Build from eclipse

    Go to your ANT Builder properties and in arguments section you can set properties using -D as below

    -Dworkspace="${workspace_loc}" -Dproject_dir="${project_loc}"
    

    (here workspace_loc and project_loc are eclipse variables). These properties can be accessed in your ANT build script like regular properties, for example:

    <echo message="${workspace}" />
    <echo message="${project_dir}" />
    

    0 讨论(0)
  • 2021-02-13 23:51

    For my project archieve.

    ProjectName <dir>
     |_ ant <dir>
         |_ ant.xml
    

    Your case can just simply change the ant xml file, the <project default="main" basedir="../"/>

    Then I can get the project root using variable of

    e.g. <echo message= "Project Root: ${basedir}" />

    0 讨论(0)
  • 2021-02-14 00:03

    I think what I'm looking for is to add the following to the build.properties file:

    project.root = ${basedir}
    

    alternatively, I can just use the basedir property whenever project.root is needed.

    I happened to be looking at the source code for ivy.properties and I saw the basedir property being used. I just tested and verified that this property works on different machines both from inside eclipse and from the command line as well as when making a call to ant from a different directory such as:

    ant -f /path/to/eclipse/workspace/projectName/build.xml
    

    When I get a minute, I will verify that this also works when importing the property file in different locations (such as inside src/main/resources/config/ivy/ivysettings.xml).

    0 讨论(0)
  • 2021-02-14 00:03

    if you need more than the trivial basedir stuff =
    Ant4Eclipse - a bunch of ant tasks for access to eclipse configurations from within ant -
    may help you. Just use it as is or grep the code and pick the relevant parts..

    0 讨论(0)
提交回复
热议问题