简体   繁体   中英

How to set lib path in ANT when the build file location changes

I am new to Ant. Following is the folder structure for my application.

  • src : source code
  • lib : jars
  • util : build.xml (ant build file)
  • output : This will have a jar file generated from source

The user should be able to copy this jar file in the output folder to anywhere and when extracted it will have

  • lib folder: contains all the libs needed
  • build.xml : ant build file to run

The user should be able to run this build.xml as "ant -f build.xml run"

The problem is, in the code structure the build.xml is under output folder, so when I write the build.xml, the lib folder path is set to ../lib/ But when the build.xml is run from the extracted folder, the build.xml is at root level and ../lib will not work since the relative path for lib would be "./lib/"

Help appreciated!

Thanks

尝试将build.xml放在util文件夹之外。或将util /添加到输出列表output.library.jar = bin /,\\ util /在build.properties文件中

Make lib dir dynamic, loaded from a property file. In the properties file local.props (that will be packaged into the jar in the root) you will have:

lib.dir=lib

You will have also another local.props file for your build process, when build.xml is in util directory. This file would have:

lib.dir=../lib

One of the first instructions in your build file must be:

<property file="local.props" />

When referencing to lib directory always use ${lib.dir} . This will make lib directory not only flexible, but also configurable on user side, as a side effect. local.props file is commonly used to provide configurability to script user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM