This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ivy fails to resolve a dependancy, unable to find cause
I'm trying to run the following build task (initIvy):
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject-build" default="package" basedir=".." xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build/build.properties"/>
<property environment="env"/>
<!-- Ant library path, including all of its plugins. -->
<path id="ant.lib.path">
<fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
</path>
<!-- CONFIGURE IVY -->
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ant.lib.path"/>
<!-- Use Ivy tasks to resolve dependencies into the local Ivy cache. -->
<target name="initIvy">
<!-- Initialize Ivy and connect to host repository. -->
<echo message="Initializing Apache Ivy and connecting to the host repository."/>
<ivy:settings url="${ivy.std.repo.settings.url}" realm="${ivy.std.repo.realm}" username="${ivy.std.repo.username}" passwd="${ivy.std.repo.password}"/>
<!-- Clear/flush the Ivy cache. -->
<echo message="Cleaning the local Ivy cache for the current build."/>
<ivy:cleancache/>
</target>
<!-- Rest of buildfile omitted for brevity. -->
</project>
When I run ant -buildfile build.xml initIvy I get the following output:
Buildfile: /<path-to-my-project>/build/build.xml
[taskdef] Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found.
initIvy:
[echo] Initializing Apache Ivy and connecting to the host repository.
BUILD FAILED
/<path-to-my-project>/build/build.xml:81: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/<path-to-my-ANT_HOME>/lib
-/home/myUser/.ant/lib
-a directory added on the command line with the -lib argument
When I go to ${ANT_HOME}/lib, I don't see any JARs labeled "antlib*.jar".
So I'm guessing I downloaded a version of Ant that did not include Antlib, and now that I'm using Ivy (which uses Antlib), the build is choking?
If this is an Antlib issue, then I believe I want one of the distros available here. If so, can someone confirm which one I should use (that only contains Antlib and not anything else), and confirm the process for installing it; i.e., is it just as simple as putting the correct JAR in ${ANT_HOME}/lib? Etc.
If this is an Ivy issue, then can someone point me in the right direction as to what could be going on?
And if this is neither Antlib nor Ivy, ditto for the question directly above. Thanks in advance!
I think you might be missing Apache IVY library. Download it from here - apache ivy Copy the jar in your ant lib directory.
For example (change version numbers as appropriate):
Download and install Ant (e.g., C:\Apps\Tools\apache-ant-1.9.7).
Download and extract Ivy (e.g., C:\Users\UserName\Downloads\apache-ivy-2.4.0)
Copy C:\Users\UserName\Downloads\apache-ivy-2.4.0\ivy-2.4.0.jar into C:\Apps\Tools\apache-ant-1.9.7\lib.
Ant is configured to use Ivy.
Related
I'm migrating a maven 1 project to maven 3. The job is almost done actually with a missing task, What I need is to get all dependency names from pom file and write them to a configuration file as one string, the job is done like below in the maven.xml, check the last 5 lines where it writes the names to a file called wrapper.conf.
How can I achive this with Maven3? Is there a maven plugin I can use for this or I need to use ant script within my pom.xml?
<goal name="service">
<mkdir dir="${maven.build.dir}/grid" />
<ant:copy todir="${maven.build.dir}/grid">
<fileset dir="resources/javaservicewrapper" />
</ant:copy>
<j:forEach var="lib" items="${pom.artifacts}">
<j:set var="dep" value="${lib.dependency}"/>
<j:if test="${dep.getProperty('service.bundle')=='true'}">
<ant:copy failonerror="true" todir="${maven.build.dir}/grid/lib">
<fileset dir="${maven.repo.local}/${dep.groupId}/jars">
<include name="${dep.artifactId}-${dep.version}.${dep.type}"/>
<j:set var="SERVCP" value="../lib/${dep.artifactId}-${dep.version}.${dep.type}:${SERVCP}" />
</fileset>
</ant:copy>
</j:if>
</j:forEach>
<attainGoal name="jar" />
<ant:copy file="target/${maven.final.name}.jar" tofile="${maven.build.dir}/grid/lib/grid.jar" />
<j:set var="SERVCP" value="${SERVCP}../lib/gridcache.jar" />
<ant:copy todir="${maven.build.dir}/gridcache/conf" file="resources/javaservicewrapper/conf/wrapper.conf" overwrite="true">
<filterset begintoken="#" endtoken="#">
<filter token="service.classpath" value="${SERVCP}"/>
</filterset>
</ant:copy>
</goal>
EDIT : The solution using build-classpath worked well but I had other problems specific to using Javaservicewrapper. So best solution I found was creating whole the script/config file by appassembler-maven-plugin and let maven-assembly plugin to copy it to the conf folder
If you have the need to create a JSW (wrapper.conf) the simplest solution would be to use the appassembler-maven-plugin which can create such files.
Have a look at the build-classpath goal of the Maven Depency Plugin. You can fast check the result on the command line:
mvn dependency:build-classpath
You can change the path to the dependeny files using the 'prefix' (mdep.prefix) property
mvn -Dmdep.prefix=myLibFolder dependency:build-classpath
You will find much more configuration parameters in the documentation, e.g. the outputFile parameter ;-)
I have following task in my build script.
<target name="upload" depends="init">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<post to="http://testapp.com/api/builds.format" verbose="true" wantresponse="true" maxwait="0">
<prop name="file" value="./release/temp.ipa"/>
<prop name="notes" value="release notes"/>
</post>
</target>
I run this build script from my mac machine. It gives the following error.
Problem: failed to create task or type post
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
I already download the ant-contrib-0.3.jar and copied it to ANT_HOME/lib directory where ANT_HOME is /usr/share/ant.
When I search the web here they have asked to use ant-contrib-version.jar as well by building the jar by ourselves using the source. But I could not run the ant script in that source since it throwing some errors.
Can some one guide me to solve this issue.
ant-contrib-0.3.jar is a pretty ancient version of Ant-Contrib. The <post> task doesn't exist in it.
Instead, you'll find <post> in the latest version of Ant-Contrib: ant-contrib-1.0b3
My build begins by defining 2 properties files, importing another build XML, and then commencing with all my other targets & tasks:
build.main.xml:
<project name="${proj.name}" default="assemble" basedir=".">
<!-- BASIC CONFIGURATIONS -->
<!-- Define build properties. -->
<property file="build.main.properties"/>
<property file="build.app.properties"/>
<!-- Imports. -->
<import file="${alt.build.file}"/>
<!-- Rest of buildscript omitted for brevity... -->
</project>
build.app.properties:
proj.name=test-proj
alt.build.file=build.app.xml
It seems that build.main.xml cannot seem to see/find any properties defined inside build.app.properties; specifically:
It cannot resolve ${proj.name}, and when I add the build.main.xml file to the Eclipse Ant view, the name of the build shows up as ${proj.name}
It cannot find build.app.xml imported from build.main.xml
What's going on here? Do ant builds only get to import one properties file or something?!? Where could I start troubleshooting?
Edit: using Eclipse editor my buildscript does not have any red/highlighted syntax errors that might be causing the ant plugin to work incorrectly, etc.
Edit: I am noticing issues with properties defined inside the build.main.properties to. If I try to echo them they don't get noticed by Ant either...
The Ant project name cannot be itself a property for the reason Jochen mentioned in his comment.
Try running your script with the -v option to see more logging. I have used a technique very similar to your <import file="${alt.build.file}"/> to branch my script based on the db platform, so there should be no problem with it.
I wondered if your property files are in the same directory then your build script is.
I've built a swing gui in eclipse that is supposed to run a bunch of code previously developed, part of which involves running ant to build the code. When I run the any script outside of the GUI (in the original project) the ant executes correctly and builds the project. However when I try and run ant programmatically it throws errors that look like the project doesn't have the necessary .jars. The code, top of the build.xml, and errors are listed below.
Code Block
File buildFile = new File("lib\\ePlay\\build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
Build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="EPlay" xmlns:ivy="antlib:org.apache.ivy.ant" default="resolve">
<dirname file="${ant.file}" property="ant.dir" />
<property name="scm.user" value="scmrel"/>
<property name="scm.user.key" value="/.ssh/scmrel/id_rsa"/>
<property name="ivy.jar" value="ivy-2.0.0.jar" />
<property name="ivy.settings.dir" value="${ant.dir}/ivysettings" />
<property name="VERSION" value="LATEST" />
<property name="tasks.dir" value="${ant.dir}/.tasks" />
<property name="deploy.dir" value="${ant.dir}/deploy" />
...
<!-- retrieve the dependencies using Ivy -->
<target name="resolve" depends="_loadantcontrib,_getivy" description=" retrieve the dependencies with Ivy">
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
<ivy:resolve file="${ant.dir}/ivy.xml" transitive="false" />
<ivy:retrieve pattern="${deploy.dir}/[conf]/[artifact].[ext]"/>
</target>
And the error
resolve:
BUILD FAILED
H:\eclipse\CLDeploySwing\lib\ePlay\build.xml:66: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-ANT_HOME\lib
-the IDE Ant configuration dialogs
Total time: 0 seconds
I've looked through my ant installation and it appears everything is there. Like I said, the original project builds successfully if build.xml is run outside of this application.
I would suggest that this is causde because your java program does not have the same classpath, where it is running, as does the normal ant build - and thus the ANT_HOME isn't the right one.
You can make sure that this is correct by passing the right enviornmental variables into the JVM, or simply a call to System.getProperty("ANT_HOME"), to see where your ANT_HOME actually is residing.
I think ${basedir} for your project is not properly calculated.
Add this line to your build.xml
<echo message="basedir='${basedir}'/>
Looking at this line
File buildFile = new File("lib\\ePlay\\build.xml");
It may be that it's 2 levels up ( I know the documentation says that it should be a parent directory of build.xml, but you are not running from the command line ).
rather than load the ivy library using the new method of using the namespace in the project declaration go old school on it.
<path id="ivy.lib.path">
<fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
I am doing something in Gradle that requires this
ant.taskdef(name: 'ivy-retrieve', classname: 'org.apache.ivy.ant.IvyRetrieve', classpath: '...path to ivy jar.../ivy-2.2.0.jar')
which in ant would be something like
<taskdef name="ivy-retrieve" classname="org.apache.ivy.ant.IvyRetrieve"/>
I know it's more klunky and simply not as nice as including the namespace declaration but it does remove some of the confusion regarding which libraries on which classpath are being loaded.
i need help using IVY as dependencies manager
my application need to load plug-ins at RUN-TIME
means while the core application is running ,user can request for a new plug-in
and install them ,
i wish to manage all installed plug-ins using the core application DB.
i want to get a pom from my plug-ins server (or some other descriptor),
and ask IVY to tell me what are the dependencies OR let IVY
install the plug-in and dependencies ,
based on the current state of my application.
( what do i have right now ,
1.jar's used by core application
2.jar's used by current installed plug-ins)
i wish for each plug-in to have independent directory
under some folder where my application is located (not a shared one)
the thing is i don't know where to start
i notice that there is no programming API for that
i located one link over the network of someone who try something similar
but look likes the code is not completed , or some variable are missing
and i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/ivy-user#ant.apache.org/msg03228.html
(where the variable "art" came for.....)
can you help me please ...
Thank you all
UPDATE
ok this what i am trying now .
i am getting some a error plus i dont know how to define my archiva server
IvySettings settings = new IvySettings();
settings.setDefaultIvyUserDir(new File("D:/programming/eclipse_projects/ivyTest/repo/"));
settings.setDefaultCache(new File("D:/programming/eclipse_projects/ivyTest/repo/cache/"));
settings.setDefaultCacheArtifactPattern("[module]/[revision]/[module]-[revision](-[classifier]");
Ivy ivy = Ivy.newInstance(settings);
ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), new File("src/movies.pom").toURL(), true);
RetrieveOptions retriveOptions = new RetrieveOptions();
retriveOptions.setUseOrigin(true);
retriveOptions.setConfs(md.getConfigurationsNames());
ivy.retrieve(md.getModuleRevisionId(), "lib/[conf]/[artifact].[ext]", etriveOptions);
this is the error i get
:: loading settings :: url = jar:file:/D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: retrieving :: org.jtpc#movies
checkUpToDate=true
confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
java.lang.RuntimeException: problem during retrieve of org.jtpc#movies: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
at org.apache.ivy.Ivy.retrieve(Ivy.java:540)
at Test.main(Test.java:52)
Caused by: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
at org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
... 2 more
Ivy can be used as a standalone java program:
java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"
The retrieve pattern can be then used to determine where files are installed, based on the ivy configuration settings
$ find lib -type f
lib/core/commons-lang.jar
lib/plugin1/commons-logging.jar
lib/plugin1/commons-codec.jar
lib/plugin2/commons-logging.jar
lib/plugin2/commons-cli.jar
lib/plugin3/commons-logging.jar
Configurations are used as a collective label or grouping of dependencies. They are similar to Maven scopes but much more flexible:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="core" description="Core application dependencies"/>
<conf name="plugin1" description="Plugin 1 dependencies"/>
<conf name="plugin2" description="Plugin 2 dependencies"/>
<conf name="plugin3" description="Plugin 3 dependencies"/>
</configurations>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.5" conf="core->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.4" conf="plugin1->default"/>
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="plugin2->default"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="plugin1,plugin2,plugin3->default"/>
</dependencies>
</ivy-module>
If you only want to download and install one set of jars, into a specified directory you can use the confs parameter:
java -jar ivy.jar -retrieve "plugin1/[artifact].[ext]" -confs plugin1
Finally, if you still want to use a programming API, you could invoke the run method called by the main class
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=markup
Update 1
Groovy has built in support for invoking ivy tasks
import groovy.xml.NamespaceBuilder
def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')
ivy.settings(file:"ivysettings.xml")
ivy.retrieve(pattern:"lib/[conf]/[artifact].[ext]")
ivy.report(toDir:'reports', graph:false)
Update 2
To set the location of your local Maven repository you need to use an ivysettings.xml file.
<ivysettings>
<settings defaultResolver='nexus' />
<resolvers>
<ibiblio name='nexus' root='http://myhost.mydomanin.com:8081/nexus' m2compatible='true' />
</resolvers>
</ivysettings>
Update 3
Just found an article that details how to invoke Ivy from Java