Library depends on library, which missing in maven central (error 404 missing library). I tired to download the same library from an external source and placed into local Maven Repository, but it's not working. How can I solve this problem?
The following artifacts could not be resolved: javax.media:jai-core:jar:1.1.3, com.sun.media:jai-codec
:jar:1.1.3: Failure to find javax.media:jai-core:jar:1.1.3 in http://repo.maven.
apache.org/maven2 was cached in the local repository, resolution will not be rea
ttempted until the update interval of central has elapsed or updates are forced
If I adds these libraries in pom of my project(just for testing local repo), it's ok (from local repo). Problem, that another library depends on them.
My pom.xml:
<dependency>
<groupId>de.intarsys.opensource</groupId> //lib in maven central
<artifactId>jPodRenderer</artifactId> //depends on libs below
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>javax.media</groupId> //in local repo
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
Can you just try it out.
I'm not sure I understood your question.
Pom.xml
<dependency>
<groupId>com.sun.media</groupId> //in local repo
<artifactId>jai_codec</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>de.intarsys.opensource</groupId>
<artifactId>iscwt</artifactId>
<version>5.5</version>
</dependency>
Make sure that the version of jar file you download has the same version with the file in pom.xml.
Make sure that you put the jar file in the correct directory.
The fastest solution is to add a Maven repository in your project source code. See here for an example on how to add a library to a custom maven repository :
http://david-codes.blogspot.com/2014/03/maven-add-custom-repository-in-your.html
There's a difference in the name:
maven was searching for jar-core, but you refer to jai_core
The first one is available on https://repository.jboss.org/maven2, the second one on maven central https://repo1.maven.org/maven2
Related
I am trying to add a jar file to the Maven dependency in my project. The settings.xml is configured to set the repository to a public repository. But this particular jar is not present in that repo. As i have the jar in my lib folder, how can i configure the Maven dependency to take this jar?
Have a look at system dependencies.
You basically need to define <scope>system</scope>.
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>
This is if you don't have your own hosted artifact repository server such as Nexus, Artifactory or Archiva.
If you do, then as Karl-Heinz suggested, you would be better off placing it there, as it's not good practice to commit binary artifacts to version control.
Another option is to set up a repository that is backed by a directory inside your project, per this answer: https://stackoverflow.com/a/2230464/433789
Changing pom.xml worked for me (jar in "/lib" directory in the root project folder) :
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/gson-2.8.6.jar</systemPath>
</dependency>
The best solution is to start using a repository manager like Nexus and put it there. Or you can use the non-maven-jar-plugin.
I have setup Sonatype Nexus with Maven and seems to be working. However, my project depends (transitively) on docbook-xsl-1.75.2 but instead of a jar there you find a zip file. Is this the reason why Nexus is not getting it, that it is a zip file? I haven't found any Nexus configuration page in the web console offering a possible filter.
I browse my Nexus repository and see it gets the pom file but nothing else.
That module has no main artifact, it's packaging type is set to "pom".
What it does have is two additional artifacts which can be retrieved using Maven module classifiers as follows:
<dependency>
<groupId>net.sf.docbook</groupId>
<artifactId>docbook-xsl</artifactId>
<version>1.75.2</version>
<classifier>resources</classifier>
<type>zip</type>
</dependency>
And
<dependency>
<groupId>net.sf.docbook</groupId>
<artifactId>docbook-xsl</artifactId>
<version>1.75.2</version>
<classifier>ns-resources</classifier>
<type>zip</type>
</dependency>
Sorry, I have no idea how you'd retrieve these as transitive dependencies.
The next day, and after restarting Nexus it pulled the dependency. I don't still understand the magic behind Nexus not seeing the dependencies while they are clearly available but at least this question is resolved.
I have one project jar oauth.
I want to add it in another maven project . I tried to change pom.xml file but no effect. Can anyone please suggest me?
I tried to add following dependency in my pom.xml file:
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapps/WEB-INF/lib/auth.jar</systemPath>
</dependency>
With the assumption that you have that auth.jar in your local repository (as it builds fine).
Why don't you give a try like this.
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Honestly speaking I don't prefer to give the jar location in my pom file and using scope as system, I leave this task to handle by Maven to resolve all the artifacts either by searching in local maven repository first(/.m2) or in MAVEN CENTRAL REPO if it is a 3rd party jar.
I have a dependency problem with maven. I used to have saxon 8.7 that is located on maven central. Then, I had to upgrade to the latests saxon-b 9.1.0.0 which is only partially on maven central.
This is a snippet of my dependencies:
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon-dom</artifactId>
<version>9.1.0.8</version>
<scope>runtime</scope>
</dependency>
The first artifact 'saxon' is available on maven central, but the secon 'saxon-dom'. Here is the artifact I want.
Can I tell maven to download the "jar" file or am I obliged to download the jar and publish it locally on my maven repo to use it as a dependency?
Did not expect to resolve this so easily :
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
<classifier>dom</classifier>
</dependency>
Basically, I can get the dependencies that are "attached" to the 'saxon' artifact using the classifier tag. Did not know about this and I found out that the tag existed when I searched for 'saxon' on Sonatype repository (which is quite good). It gave me the dependency snippet above.
Reference : http://maven.apache.org/pom.html
If the required version is not in the repo, then yes you need to do one of the following alternatives
Search for a public repo containing the required version of jar. And add the repo to your pom.xml file. OR
Download it manually, and install it locally on your machine, to help the project build completely.
I'm new to maven, I got 2 problems here:
1,How to solve missing artifact problem?
I need jcharts-0.7.5, but it's not available in Maven Central Repository. I have the jar file, but seems not easy to put it into a maven project.
2,How to fix wrong dependency scope of artifact?
I have a WAR project depends on artifact axis2-kernel, which is depending on servlet-api-2.3 with the scope of 'compile' (mistake of 'provided'), so mvn install packet the servlet-api-2.3.jar into the war file, and causes a "validateJarFile(...) - jar not loaded." error in Tomcat 7.
Number one: use a maven repository. This can be a simple Apache HTTP site with static content. But I would recommend using Sonatype Nexus or JFrog Artifactory for storing artifacts not found somewhere else.
You may find them in the JBoss repository or IBiblio (both quite big)
Number two: you can add that dependency to your pom and just set the scope you want. If you exclude the artifact you will have to add it again anyway. Maven will always prefer what is directly in you pom:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
To answer your second question: you can exclude transitive dependencies using the < exclusion > tag: http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
<project>
...
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>...</version>
<exclusions>
<exclusion><!-- declare the exclusion here -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
There are many different solutions how to add missing dependencies. For example, you could use the scope system and provide the path (you can put the JAR into the project and use a path relative to ${basedir}).
But a much better solution is to install a server like Nexus or Artifactory because they allow you to create your own repositories and they still work should the Internet fail (for example, when some idiot breaks your router or your ISP has some problems or someone drives a 18 inch double-T steel beam through a bunch of fibres).
Builds will also be much faster since the downloads will be via your local LAN instead of going around half the globe.
You can simply repeat the dependency in your POM with a different scope (your POM always wins) or you can use a dependencyManagement element.
I prefer the dependencyManagement approach because it allows you to set scopes and versions in a single place for all your projects.