Ivy can't resolve log4j from Maven Central - java

New to Apache Ivy, and can't get it to resolve the latest log4j jar from Maven Central. I'm using IvyDE to manage all of my dependencies and using all of its defaults, which I believe configure it to use either the Maven repo or Ibiblio.
This link takes you to Maven's log4j page. From here I am just using the Apache Ivy <dependency> tag provided on that page:
<dependency org="log4j" name="log4j" rev="1.2.16" >
<artifact name="log4j" type="bundle" />
</dependency>
When I add this to my ivy.xml file and save it inside Eclipse, IvyDE automatically runs an Ivy resolve...and I am getting an error:
Ivy resolve job of ivy.xml in 'myProject' has encountered a problem.
Impossible to resolve dependencies of myOrg#myProject;working#myMachine
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
(Those last 4 lines, although identical, are in fact repeated 4 times!)
Is something wrong with log4j on Maven Central? All of my other jars resolve without a hitch, and I am using the same technique for getting all of my jars. This is the only one (out of 30 or so) that is failing. Thanks in advance!

Leave out the
<artifact name="log4j" type="bundle" />
part and it will download the normal jar file.
I don't think you need the bundle-specification part and it seems (to me) like some kind of anomaly.
bundle is not even a core packaging value for maven:
The current core packaging values are: pom, jar, maven-plugin, ejb,
war, ear, rar, par. These define the default list of goals which
execute to each corresponding build lifecycle stage for a particular
package structure.

I used following :
<dependency org="log4j" name="log4j" rev="1.2.17">
<artifact name="log4j" type="jar" />
</dependency>
and it worked.

Related

NoClassDefFoundError when importing Tika 1.13 in Eclipse

I've done the following steps per the tika guide:
Add the tika-core and tika-parser dependencies to the pom.xml of the maven project
Run maven install from eclipse to produce tika-core jar and tika-parser jar
Add tika-core jar and tika-parser jar to my eclipse project build path
And I get this runtime exception when trying to run tika:
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
at com.ibm.hrl.ace.pdftotext.TikaExtracter.parse(TikaExtracter.java:33)
at com.ibm.hrl.ace.pdftotext.Main.AllPdfsToText(Main.java:116)
at com.ibm.hrl.ace.pdftotext.Main.main(Main.java:34)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
at java.net.URLClassLoader.findClass(URLClassLoader.java:600)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:786)
at java.lang.ClassLoader.loadClass(ClassLoader.java:760)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:326)
at java.lang.ClassLoader.loadClass(ClassLoader.java:741)
... 3 more
As far as I can see, when I build the jars using maven, it does add pdfbox properly... from the build log:
[INFO] Including org.apache.pdfbox:pdfbox:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:fontbox:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:pdfbox-tools:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:pdfbox-debugger:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:jempbox:jar:1.8.12 in the shaded jar.
And here are my maven dependencies:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-parsers -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.13</version>
</dependency>
</dependencies>
The problem is that if you manually add tika-core and tika-parsers jars in your build path you will not have the transitive dependencies that are listed in their own POM.
So I would suggest to:
Remove the tika-core and tika-parsers version that you have built yourself. Instead you should rely on the versions that are available on central. This will ensure that another one building your project will get the same jar (and not a locally built one)
You have two options
(Option A, use Maven) Do not add manually into Eclipse build path the jars. Rely either or built-in Maven plugin for Eclipse (m2e for instance) or use Eclipse plugin for maven (call mvn eclipse:eclipse to update .classpath and .project).
(Option B, without Maven) If you cannot use Maven for your project, you will have to add not only tika-parsers and tika-core jars, but all (most of) the transitive dependencies needed by these project (including for instance specific library per format [POI for Office, pdfbox for PDF...). You can get a list of the dependencies by typing mvn dependency:list in the folder containing the pom of tika-parsers.

How to publish artifacts to Artifactory with different names? [duplicate]

I published few atifacts of a component to a maven repository using different configurations of ivy. As an example, I took the following way (Ivy Documentation) to do the same..
<ivy-module version="1.0">
<info organisation="org.apache" module="filter"/>
<configurations>
<conf name="api" description="only provide filter framework API"/>
<conf name="homemade-impl" extends="api" description="provide a home made implementation of our api"/>
</configurations>
<publications>
<artifact name="filter-api" type="jar" conf="api" ext="jar"/>
<artifact name="filter-hmimpl" type="jar" conf="homemade-impl" ext="jar"/>
</publications>
</ivy-module>
According to the above configuration, the artifacts that are produced are filter-api.jar and filter-hmimpl.jar, and I generated a pom file filter.pom and published this into a maven repository.
Now, when I am trying to resolve the artifact filter-api in another component using the following..
<dependency org="org.apache" name="filter" rev="3.1" conf="default->api"/>
But it is not working, I believe my filter.pom should contain some modules like this, to make it work..
<modules>
<module>api</module>
<module>homemade-impl</module>
</modules>
Am I correct, and if yes how can I map different conf's of ivy to modules in maven.
Publishing mutliple files to a Maven repository is tricky because Maven modules normally contain a single artifact. Maven modules do support additional module artifacts, which are referenced in a Maven dependency using the "classifier" attribute.
The following answers provide examples of publishing multiple files to a Maven module:
how to publish 3rdparty artifacts with ivy and nexus
Convert ivy.xml to pom.xml
Observe that the ANT scripts are using the makepom to generate POM files and that these files are considered artifacts published (part of the ivy publications section).
For more background you might be interested in the following answer that deals with the differences between Maven "scopes" and ivy "confgurations".
How are maven scopes mapped to ivy configurations by ivy
Finally, if your ivy build uses configurations, it's possible to configure the makepom task to map between configurations and scopes:
<ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/${ivy.module}.pom"/>
<mapping conf="api" scope="compile"/>
</ivy:makepom>
Most likely, the problem is with the dependency declaration. You pull the dependency into your 'default' configuration with conf="default->api". But you really want them in the "compile" conf, to include them in your compile classpath.

Ant: How to include only certain transitive dependencies from the artifact?

Just as an example, suppose I only need hamcrest in junit:
<dependency org="junit" name="junit" rev="4.7">
<include name="hamcrest*"/>
</dependency>
However it seems ant still pulls everything in junit. Maybe I misunderstood something?
Hamcrest is not longer a junit dependency. Take a look at the POM file for the module, the dependencies section is empty:
junit 4.7
Reportedly it has been incorporated into the junit jar (See MAVENUPLOAD-1651)
This explains why the following dependency will only retrieve a single jar:
<dependency org="junit" name="junit" rev="4.7"/>

Ivy not resolving transitive dependencies from public maven repos

Considering the following ivy dependencies,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
They depend on public maven repos mirrored by
http ://myivyserver:8888/mirrored/ .
as specified by the ivysettings resolver chaining to ...
<url name="mirrored" m2compatible="true">
<artifact
pattern="http://myivyserver:8888/mirrored/${maven2.artifact.pattern}" />
</url>
Where I can see the mirrored directory completely replicating the artefacts of remote maven repos.
I am used to Maven and the seeing the buildpath on eclipse showing maven dependencies.
Now, I am creating Ivy-dependency for a project. I am expecting to see similar, and I do see, a similar Ivy dependency node showing all the jars due to the Ivy eclipse pluggin.
However, the Ivy dependency node in eclipse buildpath does not show any jars transitively specified by the mirrored poms.
For example,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
both dependencies’ pom specify dependency on javax.ws.rs (jsr311-api)
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
However javax.ws.rs(jsr311-api) does not show up on the buildpath library of the ivy managed project, as a Maven managed one would.
What further more would I have to do to get ivy plugin to resolve transitive dependencies that are due to maven poms?
Thank you.
URL resolver considers maven layout but not pom dependencies. When I was implementing this functionality ibiblio resolver was able to resolve pom's dependencies.
http://ant.apache.org/ivy/history/latest-milestone/resolver/ibiblio.html
<ibiblio name="maven2" m2compatible="true" root="http://myivyserver:8888/mirrored">
I haven't used it long because I preferred non-transitive dependencies in my code so I've finished with using pure url resolver.

Hudson plug-in not publishing all artifacts to Artifactory

I've got a small Java project setup to build continuously through a Hudson server. I'd like to publish the build artifacts to an Artifactory server as a post-build step so, naturally, I'm using the Hudson-Artifactory plug-in to facilitate this. The local publish appears to work just fine - it publishes the two artifacts (both .jar files) and the resolved ivy.xml file as expected. When I request a build on the Hudson server, however, only one of my two artifacts gets published.
The build creates the following artifacts:
ftpSvc.jar
ftpSvc-lib.jar
My ivy.xml file looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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="esf"
status="integration"
module="ftpSvc"
revision="SNAPSHOT" />
<publications>
<artifact name="ftpSvc" ext="jar"/>
<artifact name="ftpSvc-lib" ext="jar" type="lib" />
</publications>
<!--list the dependencies of this project-->
<dependencies>
<dependency org="commons-net" name="commons-net" rev="1.3.0" />
</dependencies>
</ivy-module>
The two artifacts are clearly called out in the <publications> section. The build target in my build.xml file looks like this:
<target name="publish_local" description="publish artifacts locally">
<echo>organisation: ${ivy.organisation}</echo>
<echo>module: ${ivy.module}</echo>
<echo>status: ${ivy.status}</echo>
<echo>revision: ${ivy.revision}</echo>
<echo>local dir: ${ivy.default.ivy.user.dir}</echo>
<ivy:publish
resolver="local"
update="true"
verwrite="true"
srcivypattern="${bundle.jar.dir}/ivy.xml"
artifactspattern="${bundle.jar.dir}/[artifact].[ext]" />
</target>
The artifactspattern grabs all defined artifacts from the build directory - nothing fancy going on here. Lastly, the resolver chain in my ivysettings.xml file looks like this (server names changed to protect the innocent):
<resolvers>
<chain name="main">
<ibiblio name="main" m2compatible="true" root="http://my.server.employer.com:8080/artifactory/repo" />
<filesystem name="local">
<ivy pattern="${ivy.default.ivy.user.dir}/local/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="${ivy.default.ivy.user.dir}/local/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</filesystem>
</chain>
</resolvers>
It's all rather routine stuff and, as mentioned above, the local publish works fine. Here's a peek at the console output when I build through Eclipse:
publish_local:
[echo] organisation: esf
[echo] module: ftpSvc
[echo] status: integration
[echo] revision: SNAPSHOT
[echo] local dir: C:\Users\myusername\.ivy2
[ivy:publish] :: publishing :: esf#ftpSvc
[ivy:publish] published ftpSvc to C:\Users\myusername\.ivy2/local/esf/ftpSvc/SNAPSHOT/ftpSvc-SNAPSHOT.jar
[ivy:publish] published ftpSvc-lib to C:\Users\myusername\.ivy2/local/esf/ftpSvc/SNAPSHOT/ftpSvc-lib-SNAPSHOT.jar
[ivy:publish] published ivy to C:\Users\myusername\.ivy2/local/esf/ftpSvc/SNAPSHOT/ivy-SNAPSHOT.xml
Both .jar files and the resolved ivy.xml file get published as expected. On my Hudson server, I've got the Artifactory Configuration settings configured thusly (again, some details have been changed to obscure my true superhero identity):
Artifactory server: http://my.server.employer.com:8080/artifactory
Target repository: target-repository
Ivy pattern: [organisation]/[module]/[revision]ivy-[revision].xml
Artifact pattern: "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
As you can see, the Ivy and Artifact patterns are exactly the same as the patterns in my local resolver from my ivysettings.xml file. Thus, when the build is run on the Hudson server, I'd expect the exact same artifacts to be published to my Artifactory server.
Let's take a look at the console output from the latest build on my Hudson server:
publish_local:
[echo] organisation: esf
[echo] module: ftpSvc
[echo] status: integration
[echo] revision: SNAPSHOT
[echo] local dir: /usr/share/tomcat6/.ivy2
[ivy:publish] :: publishing :: esf#ftpSvc
Collecting Module information for module: ftpSvc
Module location: /usr/share/tomcat6/.hudson/jobs/ftpSvc-ivy/workspace/trunk/out/jars/ftpSvc.jar
[ivy:publish] published ftpSvc to /usr/share/tomcat6/.ivy2/local/esf/ftpSvc/SNAPSHOT/ftpSvc-SNAPSHOT.jar
Collecting Module information for module: ftpSvc
Module location: /usr/share/tomcat6/.hudson/jobs/ftpSvc-ivy/workspace/trunk/out/jars/ftpSvc-lib.jar
[ivy:publish] published ftpSvc-lib to /usr/share/tomcat6/.ivy2/local/esf/ftpSvc/SNAPSHOT/ftpSvc-lib-SNAPSHOT.jar
Collecting Module information for module: ftpSvc
Module location: /tmp/ivy2450884590736960955.xml
[ivy:publish] published ivy to /usr/share/tomcat6/.ivy2/local/esf/ftpSvc/SNAPSHOT/ivy-SNAPSHOT.xml
Build finished triggered
Deploying artifact: http://my.server.employer.com:8080/artifactory/target-repository/esf/ftpSvc/SNAPSHOT/ftpSvc-SNAPSHOT.jar
Deploying artifact: http://my.server.employer.com:8080/artifactory/target-repository/esf/ftpSvc/SNAPSHOT/ftpSvc-SNAPSHOT.xml
Deploying build info to: http://my.server.employer.com.com:8080/artifactory/api/build
Dubya' Tee Eff!? Once again, the local publish appears to work just fine, publishing both jars and the ivy.xml file to the local/esf/ftpSvc/SNAPSHOT/ directory on the Hudson server. The Artifactory plug-in, on the other hand, gets everything totally wrong. Not only does it fail to publish one of the two jars, it renames the ivy.xml file incorrectly.
Are there any Hudson/Ivy/Artifactory experts out there that can shed some light on what's going on here? I've got multiple projects that are exhibiting the exact same behavior. Any and all assistance in resolving this problem would be greatly appreciated.
Hey, I haven't used that plugin, but I would try removing the dash from the name ftpSvc-lib and/or removing type="lib" from its artifact element, just to see what happens.
I got the same problem, filled a bug on the JFrog Jira, the bug has been marked resolved today, but as you can see in my comments on the Jira, I'm still confused about this resolution.
https://issues.jfrog.org/jira/browse/IAP-26?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
If anyone has an idea, any input would be great...

Categories