5

For example, when I open a well developed opensource project (like lucene) into Eclipse (with both ant build.xml and ivy ivysetting.xml), I can run ant with build.xml to build the whole project successfully.

However, the project is full of errors in a mess of .java classes. This is caused by unlinking to the external jars. These jars are already download by ivy and stored in {user}/.ivy2/cache/. Also, when I manually put each of these jars into the build path of this project, the errors are gone.

Can ivy or ivyDE or some other tools put the jars into the JAVA build path automatically?

Here is the 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>

2 Answers2

1

It would if you use the Ivy Eclipse plugin. If you have it installed, you'll need to add the IVY runtime to the build path of the project. This can be done via Project Properties->Java Build Path under the Libraries tab, select Add Library then select IvyDE Managed Dependencies.

Once that's done, an Ivy resolve will add all the jars specified in ivy.xml to the project's build path.

Ali Cheaito
  • 3,746
  • 3
  • 25
  • 30
  • My ivyDE is 2.2, and it is done via Project Properties->Java Build Path under the Libraries tab, select Add Library then select IvyDE Managed Dependencies. And, Main: Ivy file: ivy-setting.xml, Classpath: checked "Enable project specified settings", and checked the "Resolve dependencies in workspace". However, when I resolve the project it did not work. Add I added the xml file to the description of the question. – Brian Zhaoning Zhang Mar 12 '15 at 01:28
  • "it did not work" in what way? did you get some sort of an error? do you see the Ivy library in the classpath? Does it have any jars in it? – Ali Cheaito Mar 12 '15 at 12:54
  • There is a Ivy Library in the classpath, but with no jars inside. I should have to add the jars manually from the ivy cache into the classpath to resolve the displayed errors in the source code view. – Brian Zhaoning Zhang Mar 14 '15 at 01:20
  • @BrianZhaoningZhang ... The default behavior of IveDE is to put the needed jars in that Ivy libraries. Either the ivy.xml file doesn't have the correct dependencies in it for that project, or the resolve is erroring out. – Ali Cheaito Mar 16 '15 at 13:37
-1

You need to add ivysettings.xml file to your project and set it in Preferences (Window --> Preferences --> Ivy --> Settings: Ivy settings path). When it is absent, ivy doesn't know where to look for dependencies.

(Maybe it is enough to add the file to one of your projects, but I'm not sure.)

agad
  • 2,192
  • 1
  • 20
  • 32