ivy或ivyDE能否在Eclipse中自动将相关jar添加到JAVA构建路径库中?

Posted

技术标签:

【中文标题】ivy或ivyDE能否在Eclipse中自动将相关jar添加到JAVA构建路径库中?【英文标题】:Can ivy or ivyDE add related jars into JAVA build path library automatically in Eclipse? 【发布时间】:2015-05-13 11:36:03 【问题描述】:

例如,当我在 Eclipse 中打开一个开发良好的开源项目(如 lucene)时(同时使用 ant build.xml 和 ivy ivysetting.xml),我可以使用 build.xml 运行 ant 以成功构建整个项目。

但是,该项目在一堆乱七八糟的 .java 类中充满了错误。这是由取消链接到外部 jar 引起的。这些 jars 已经被 ivy 下载并存储在 user/.ivy2/cache/ 中。此外,当我手动将这些 jar 中的每一个放入该项目的构建路径时,错误就消失了。

ivy或ivyDE或其他一些工具可以自动将jar放入JAVA构建路径吗?

这里是 ivy-setting.xml:

<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info
        organisation=""
        module="lucene-5.0.0"
        status="integration">
	</info>
<ivysettings>
  <settings defaultResolver="default"/>
  
  <property name="local-maven2-dir" value="$user.home/.m2/repository/" />
  
  <properties file="$ivy.settings.dir/ivy-versions.properties" override="false"/>
  
  <include url="$ivy.default.settings.dir/ivysettings-public.xml"/>
  <include url="$ivy.default.settings.dir/ivysettings-shared.xml"/>
  <include url="$ivy.default.settings.dir/ivysettings-local.xml"/>
  <include url="$ivy.default.settings.dir/ivysettings-main-chain.xml"/>

  <caches lockStrategy="artifact-lock" resolutionCacheDir="$common.build.dir/ivy-resolution-cache" /> 

  <resolvers>
    <ibiblio name="sonatype-releases" root="https://oss.sonatype.org/content/repositories/releases" m2compatible="true" />
    <ibiblio name="maven.restlet.org" root="http://maven.restlet.org" m2compatible="true" />
    <ibiblio name="releases.cloudera.com" root="http://repository.cloudera.com/content/repositories/releases" m2compatible="true" />
    
    <!-- needed only for newer svnkit releases, e.g. 1.8.x -->
    <ibiblio name="svnkit-releases" root="http://maven.tmatesoft.com/content/repositories/releases" m2compatible="true" />

    <!-- you might need to tweak this from china so it works -->
    <ibiblio name="working-chinese-mirror" root="http://uk.maven.org/maven2" m2compatible="true" />
    
    <!--
    <filesystem name="local-maven-2" m2compatible="true" local="true">
      <artifact
          pattern="$local-maven2-dir/[organisation]/[module]/[revision]/[module]-[revision].[ext]" />
      <ivy
          pattern="$local-maven2-dir/[organisation]/[module]/[revision]/[module]-[revision].pom" />
    </filesystem>
    -->

    <chain name="default" returnFirst="true" checkmodified="true" changingPattern=".*SNAPSHOT">
      <resolver ref="local"/>
      <!-- <resolver ref="local-maven-2" /> -->
      <resolver ref="main"/>
      <resolver ref="maven.restlet.org" />
      <resolver ref="sonatype-releases" />
      <resolver ref="releases.cloudera.com"/>
      <!-- <resolver ref="svnkit-releases" /> -->
      <resolver ref="working-chinese-mirror" />
    </chain>
  </resolvers>

</ivysettings>
</ivy-module>

【问题讨论】:

【参考方案1】:

如果您使用Ivy Eclipse plugin 会这样。如果已安装,则需要将 IVY 运行时添加到项目的构建路径中。这可以通过 Libraries 选项卡下的 Project Properties->Java Build Path 来完成,选择 Add Library 然后选择 IvyDE Managed Dependencies。

完成后,Ivy 解析会将 ivy.xml 中指定的所有 jar 添加到项目的构建路径中。

【讨论】:

我的 ivyDE 是 2.2,它是通过 Libraries 选项卡下的 Project Properties->Java Build Path 完成的,选择 Add Library 然后选择 IvyDE Managed Dependencies。并且,主要:常春藤文件:ivy-setting.xml,类路径:选中“启用项目指定设置”,并选中“解决工作空间中的依赖关系”。但是,当我解决该项目时,它不起作用。添加我将xml文件添加到问题的描述中。 “它不起作用”以什么方式?你有什么错误吗?你在类路径中看到了 Ivy 库吗?里面有罐子吗? 类路径中有一个常春藤库,但里面没有jar。我应该必须手动将 jars 从 ivy 缓存添加到类路径中,以解决源代码视图中显示的错误。 @BrianZhaoningZhang ... IveDE 的默认行为是将所需的 jar 放入该 Ivy 库中。 ivy.xml 文件中没有该项目的正确依赖项,或者解析出错。【参考方案2】:

您需要将ivysettings.xml 文件添加到您的项目并在首选项中进行设置(窗口--> 首选项--> 常春藤--> 设置:常春藤设置路径)。当它不存在时,ivy 不知道去哪里寻找依赖关系。

(也许将文件添加到您的项目之一就足够了,但我不确定。)

【讨论】:

以上是关于ivy或ivyDE能否在Eclipse中自动将相关jar添加到JAVA构建路径库中?的主要内容,如果未能解决你的问题,请参考以下文章

Eclipse安装ivy插件

无法使用 Eclipse 中的 IvyDE 插件从常春藤缓存中删除过时的工件

ivy 和 ivyde 以及 FileSystem 解析器

ivy + eclipse 运行时依赖部署

在 WAR 文件中排除 Ivy 依赖项

如何将 Ivy 的依赖项添加到 Eclipse PDE 目标平台?