Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

ivy - Split retrieved artifacts in two separate lib directories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...