eclipse中如何使用ivy+ivyDE在lib和web-inf/lib中放置不同的jar包 [英] How to use Ivy + IvyDE in eclipse to put different jars in lib and web-inf/lib

查看:26
本文介绍了eclipse中如何使用ivy+ivyDE在lib和web-inf/lib中放置不同的jar包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在尝试将 Ivy 添加到我的项目中,该项目输出一个 WAR 文件.一些依赖项,如 RESTEasy 和 Jackson 在运行时在 JBoss 中可用,所以我不希望那些在我的 war/WEB-INF/lib 文件夹中.其他库无法通过 JBoss 模块使用,因此我想将它们包含在我的项目中.

So, I'm trying to add Ivy to my project, which outputs a WAR file. Some dependencies, like RESTEasy and Jackson are available at runtime in JBoss, so I don't want those in my war/WEB-INF/lib folder. Others libraries are not available via JBoss modules, so I want to include those in my project.

** 注意:在 Eclipse 中,我使用的是动态 Web 模块方面.这个想法是让 IvyDE 将所需的运行时依赖项复制到 war/WEB-INF/lib 中.

** NOTE: In eclipse, I'm using the Dynamic Web Module facet. The idea is to get IvyDE to copy the desired runtime dependencies into war/WEB-INF/lib.

最初我创建了 2 个 ivy 配置文件:

Initially I created 2 ivy configuration files:

  • ivy.xml - 运行时(未包含在 WAR 中)
  • ivy_web.xml - 包含在战争中

然后我使用 GUI 来配置与 Ant 检索任务等效的 IDE.因此,在我不想在 IDE 中使用的 ANT 构建文件中,我有以下内容:

Then I used the GUI to configure the IDE equivalent of the Ant retrieve task. So, in my ANT build file, which I don't really want to use in my IDE, I have the following:

<ivy:retrieve pattern="war/WEB-INF/lib/[artifact]-[revision].[ext]" file="ivy-web.xml" type="jar" />
<ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" file="ivy.xml" type="jar" />

  • 目前还不允许使用图像 :-(
  • 我在另一个帖子评论中注意到(在 Eclipse 中映射多个常春藤文件) 他们提到只使用 1 个 ivy.xml - 但我不太确定如何到达那里?

    I noticed in another post comment (mapping multiple ivy files in Eclipse) they mention using only 1 ivy.xml - but I'm not quite sure how to get there?

    哦,我也注意到了这一点:IvyDE + WTP:如何解决 WTP 忽略 ivy 库的问题? - 但是我的项目没有使用正确的方面,我宁愿不添加它们.

    Oh, I also noticed this as well: IvyDE + WTP: How to workaround that ivy library is ignored by WTP? - however my project doesn't use the right kind of facets, and I'd rather not add them.

    因此,在阅读此 (https://stackoverflow.com/a/16575318/880884) 帖子后,我向我的项目添加了编译和运行时配置.它看起来像这样:

    So, after reading this (https://stackoverflow.com/a/16575318/880884) post, I added compile and runtime configurations to my project. It looks about like this:

    <configurations>
        <conf name="compile" description="used for building"/>
        <conf name="runtime" description="used for running"/>
    </configurations>
    
     <dependencies>
        <!-- compile -->
        <dependency org="org.codehaus.jackson" name="jackson-core-asl" rev="1.9.2" conf="compile->default"/>
        <dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.9.2" conf="compile->default"/>
        <dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.9.2" conf="compile->default"/>
    
    
        <!-- runtime -->
        <dependency org="com.google.guava" name="guava" rev="14.0.1" conf="runtime->default"/>
        <dependency org="com.google.inject" name="guice" rev="3.0"  conf="runtime->default"/>
        <dependency org="aopalliance" name="aopalliance" rev="1.0" conf="runtime->default"/>
        <dependency org="javax.inject" name="javax.inject" rev="1" conf="runtime->default"/>
    </dependencies>
    

    再次,我尝试只添加一个ivy.xml.接下来我去项目属性>常春藤>检索列表>添加-添加了2个不同的配置,一个用于编译,映射到/lib.另一个使用运行时"配置并为检索模式指定war/WEB-INF/lib/[artifact]-[revision].[ext]".

    Again, I tried to add just the one ivy.xml. Next I went the Project properties > Ivy > Retrieve List > Add - Added 2 different configurations, one for compile, which maps to /lib. The other uses the 'runtime' configuration and specifies "war/WEB-INF/lib/[artifact]-[revision].[ext]" for the retrieve pattern.

    然而,我最终在我的 war/WEB-INF/lib/中得到了编译",这不是我想要的.我只希望将运行时依赖项复制到那里.

    However, I end up with the "compile" in my war/WEB-INF/lib/, which is NOT what I wanted. I ONLY want the runtime dependencies copied there.

    推荐答案

    我认为您缺少的一点是在检索任务中使用配置:

    I think the bit you're missing is the use of configurations, in the retrieve task:

    <ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" conf="compile" />
    

    配置是 ivy 将依赖项组合在一起的机制.

    Configurations are ivy's mechanism to group dependencies together.

    ├── build.xml
    ├── ivy.xml
    └── target
        ├── lib
        │   ├── jackson-core-asl-1.9.2.jar
        │   ├── jackson-jaxrs-1.9.2.jar
        │   ├── jackson-mapper-asl-1.9.2.jar
        │   └── jackson-xc-1.9.2.jar
        ├── reports
        │   ├── ivy-report.css
        │   ├── myorg-mymodule-compile.html
        │   └── myorg-mymodule-runtime.html
        └── war
            └── WEB-INF
                └── lib
                    ├── aopalliance-1.0.jar
                    ├── asm-3.1.jar
                    ├── cglib-2.2.1-v20090111.jar
                    ├── guava-14.0.1.jar
                    ├── guice-3.0.jar
                    └── javax.inject-1.jar
    

    build.xml

    <project name="demo" default="retrieve" xmlns:ivy="antlib:org.apache.ivy.ant">
    
       <property name="build.dir" location="target"/>
    
        <target name="resolve" description="Use ivy to resolve dependencies">
            <ivy:resolve/>
            <ivy:report todir='${build.dir}/reports' graph='false' xml='false'/>
        </target>
    
        <target name="retrieve" depends="resolve" description="Populate directories">
          <ivy:retrieve pattern="${build.dir}/lib/[artifact]-[revision].[ext]" conf="compile" />
          <ivy:retrieve pattern="${build.dir}/war/WEB-INF/lib/[artifact]-[revision].[ext]" conf="runtime" />
        </target>
    
        <target name="clean" description="Cleanup build files">
            <delete dir="${build.dir}"/>
        </target>
    
        <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
            <ivy:cleancache/>
        </target>
    
    </project>
    

    注意事项:

    • 上面的示例还生成了一个依赖项解析报告,我发现它对于查看每个配置的内容非常有用.
    <ivy-module version="2.0">
      <info organisation="myorg" module="mymodule"/>
    
      <configurations>
        <conf name="compile" description="used for building"/>
        <conf name="runtime" description="used for running"/>
      </configurations>
    
      <dependencies>
        <!-- compile -->
        <dependency org="org.codehaus.jackson" name="jackson-core-asl" rev="1.9.2" conf="compile->default"/>
        <dependency org="org.codehaus.jackson" name="jackson-xc" rev="1.9.2" conf="compile->default"/>
        <dependency org="org.codehaus.jackson" name="jackson-jaxrs" rev="1.9.2" conf="compile->default"/>
    
        <!-- runtime -->
        <dependency org="com.google.guava" name="guava" rev="14.0.1" conf="runtime->default"/>
        <dependency org="com.google.inject" name="guice" rev="3.0" conf="runtime->default"/>
        <dependency org="aopalliance" name="aopalliance" rev="1.0" conf="runtime->default"/>
        <dependency org="javax.inject" name="javax.inject" rev="1" conf="runtime->default"/>
      </dependencies>
    </ivy-module>
    

    这篇关于eclipse中如何使用ivy+ivyDE在lib和web-inf/lib中放置不同的jar包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆