Split retrieved artifacts in two separate lib directories

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:16:57

问题


In my web application, there are two separate lib directories:

  • /lib, and
  • /web/webroot/WEB-INF/lib.

The idea behind it is that libraries in the latter one are used by front-end code only, and the first one by both the front-end and the business logic code. There is a class loader in place which lets the business logic code not see the jars in /web/webroot/WEB-INF/lib.

How can I tell ivy that certain dependencies should go to the second directory while all others go to first one?

It's not trival since the the web class loader can see jars in both directories and I don't want jars to be in both directories.


回答1:


Configurations are used to create logical groupings of dependencies:

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>
    <configurations>
        <conf name="frontEnd" description="Jars used by front end"/>
        <conf name="businessLogic" description="Jars used for business logic"/>
    </configurations>
    <dependencies>
        <dependency org="commons-lang"    name="commons-lang"    rev="2.5"   conf="businessLogic->default"/>
        <dependency org="commons-codec"   name="commons-codec"   rev="1.4"   conf="businessLogic->default"/>
        <dependency org="commons-cli"     name="commons-cli"     rev="1.2"   conf="frontEnd->default"/>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="frontEnd->default"/>
    </dependencies>
</ivy-module>

The ivy retrieve ant task can use these configurations to populate your directories:

build.xml

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:retrieve conf="businessLogic" pattern="lib/[artifact].[ext]"/>
    <ivy:retrieve conf="frontEnd" pattern="web/webroot/WEB-INF/lib/[artifact].[ext]"/>
</target>

Example

$ find . -type f
./build.xml
./ivy.xml
./lib/commons-lang.jar
./lib/commons-codec.jar
./web/webroot/WEB-INF/lib/commons-cli.jar
./web/webroot/WEB-INF/lib/commons-logging.jar


来源:https://stackoverflow.com/questions/4071009/split-retrieved-artifacts-in-two-separate-lib-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!