I am new to Maven and I am currently using the m2e plugin for Eclipse.
Question 1:
When searching for an artifact (atmosphere-runtime) in the default central repository (right click project: Maven -> add dependancy), a list of results is returned.
However upon adding the dependency I receive the following error message:
Missing artifact org.atmosphere:atmosphere-runtime:bundle:1.0.2
If I search for the artifact on the maven web site I am able to find and download the jar manually (see here). I have tried cleaning/updating/reloading the project, updating/reindexing/rebuiling the central maven repo and restarting Eclipse, but nothing seems to help.
Is there a reason why I am getting this error?
Question 2:
A tutorial I am following suggested adding the following repositories to the pom to download the above artifact:
<repositories>
<repository>
<id>Sonatype snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>Sonatype releases</id>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
</repositories>
This works and I am able to download the required artifacts if I manually specify the dependencies in the pom.xml file.
However, if I try and search for the artifacts using the eclipse search (right click project: Maven -> add dependancy), no results are returned from the two new repositories.
Is it possible to include these two new repositories in the search?
For your 1st question. Maven central has only a "jar" but you seemed to be requiring a bundle instead. So you have to change your dependency to "jar" which means to define the dependency like this:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.2</version>
</dependency>
instead of:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.2</version>
<type>bundle</type>
</dependency>
The best thing to solve the problem in your 2nd Question is to use a repository manager like Nexus and define those two repositories in the repository manager.
The https://oss.sonatype.org/content/repositories/snapshots defines the SNAPSHOT's of artifacts which are in Maven Central whereas the second one is the repository which is regularly synchronized into Maven Central. So in my opinion you don't need those two repository separately. If you want to search the content of the two above repositories you can use the search of that: https://oss.sonatype.org/ where you have the access to a Nexus repository which can be used for searching as well.
To your 2. question. Expand Project Repositories in Maven Repositories view and right click on added repositories and check Enable Full Index.
To your 1. question. Enable full index for central repository if not enabled, and try to Update Index/Rebuild Index.
Related
I am new to maven and find that some artifacts are not on Maven central repository, so I need to manually add repository 's id and url in pom.xml. It's relatively easy if I were the original developer of the project, but hard as a maintainer.
For example, I get a Maven project from GitHub. The project has an dependency on org.openhab.addons.bundles:org.openhab.addons.reactor.bundles:3.2.0-SNAPSHOT, which is not on Maven central repository.
What I do is Google org.openhab.addons.bundles org.openhab.addons.reactor.bundles to try finding which public repository should I add in pom.xml.
Like
<repositories>
<repository>
<id>openhab</id>
<url>https://openhab.jfrog.io/openhab/libs-release/</url>
</repository>
</repositories>
My question is that given a Maven artifact's coordinate, how can I programmatically find which repository should I add in pom.xml?
Thank you.
I am new to Maven Project. I am making changes to one of the open source maven project. I am facing a problem in adding a library to the project. So far i have done this :-
I added a library named jni4net.j-0.8.8.0.jar to the resources folder of the project.
I right clicked the jar(in Intellij) and clicked 'Add as library'.
Then in the pom.xml i added:-
<dependency>
<groupId>jar.0.8.8.0.jni4net</groupId>
<artifactId>jar.0.8.8.0.jni4net</artifactId>
<version>0.8.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/jni4net.j-
0.8.8.0.jar</systemPath>
</dependency>
But when i build this project(build is successful, test cases are running) and use this it throws following error:-
java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
Please help me resolve it. I am new to maven and pom. I have looked at various answers, but not getting it right.
PS - I named groupId and artifactID as just reverse of jar file
This is not the right way to add that dependency.
All you need is:
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
The dependency will be retrieved from Maven Central when you build.
Using <systemPath>...</systemPath> is highly discouraged as it usually ties your project to a local environment.
Since jni4net.j dependency is available in maven central, You don't have to download and put the dependency manually. Maven will download and store the dependency locally in `'.m2' folder. Just add dependency as bellow.
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
I am trying to revive my old project. I want to use maven for it and I want to add AbsoluteLayout dependency. I am kinda new in maven so I have no idea what is wrong. I have found that this should work:
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE802</version>
</dependency>
but I only get this error:
Failed to execute goal on project XXX: Could not resolve dependencies for project xx.xxxx:XXX:jar:1.0-SNAPSHOT: Failure to find org.netbeans.external:AbsoluteLayout:jar:RELEASE802 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
After this I manually added this dependency from my netbeans folder in my computer. And it is working. Is there another way how to add this dependency? I would like to include it in my pom file. Any ideas?
You need to add a Netbeans repository to your POM:
<repositories>
<repository>
<id>netbeans</id>
<name>Netbeans rep</name>
<url>http://bits.netbeans.org/maven2/</url>
</repository>
</repositories>
I added the below dependency block to my POM and after updating my maven indices it worked just fine.
<!-- https://mvnrepository.com/artifact/org.netbeans.external/AbsoluteLayout -->
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE802</version>
</dependency>
So you might want to try updating your maven indices and see if that does it for you. This dependency block came directly from mvnrepository.com/, and worked without me needing to add any special repo as far as I'm aware.
Look like that dependency is not exists in the public repository, you can register an account and upload it, or, from my view point is better, you can setup your own private maven repository server, there many software support to do this, for example JFrog Artifactory, it is easy to install and manipulate.
When I run
mvn compile
I get package com.ibm.icu.util does not exist. So I downloaded the ICU4J jar and installed it into the local repository. I confirmed it's in .m2/repository/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar. Inside that jar file is the missing class file com/ibm/icu/util/Calendar.class. Then I added the following into the dependencies section of pom.xml:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>3.4.4</version>
</dependency>
But when I run mvn compile again, I get the same error. What am I doing wrong?
You should avoid adding dependencies manually.
If you don't know a groupId and artifactId of the dependency you need, search for it at http://mvnrepository.com/. Usually, groupId matches the package names in the jar file.
For your case, the dependency is already there: http://mvnrepository.com/search?q=com.ibm.icu
So, go to http://mvnrepository.com/artifact/com.ibm.icu/icu4j and get the version of the dependency you need, e.g. 55.1: http://mvnrepository.com/artifact/com.ibm.icu/icu4j/55.1
Grab maven dependency xml and put it to your pom.xml file:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>55.1</version>
</dependency>
If you didn't find your dependency try to find it in google. Sometimes the dependency may be found in some corporate public repositories, not in a central. In this case you need to add the third-party repository to repositories section of your pom.xml.
If you're unable to find your dependency in the public repository then you have three options:
A. Install jar to internal repository server (e.g. nexus)
B. Put the JAR file in your project sources and declare project maven repository :
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/my-repo</url>
</repository>
</repositories>
Important: You should keep the maven repository layout in your local repository.
C. [Bad Practice] Use maven install plugin to install your custom jar to local repository on your machine. But it's a badIt's not recommended.
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom
D. [Bad Practice] Use system dependency with absolute path to the JAR file, although it's a bad practice and should be avoided.
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
You should not be manually installing things into the maven repository directory. That directory is maintained by maven itself.
The way dependencies work is that when you run mvn compile or some other goal, it will connect to the maven central repository and download the needed dependencies and their dependencies.
If you manually install a jar file, it may not have it's dependencies. That icu artifact will likely have other things it depends on. Maven will automatically resolve these dependencies.
I would recommend using mvn clean install this will clean the target directory and rebuild everything.
If it fails to download, then you likely need to change the maven configuration. For example, if you are behind a proxy server you need to configure maven with the proxy credentials.
Also, if you manually copied anything into the .m2/repository/ directory you should delete it and let maven put it in there correctly instead.
The beauty of maven is that you don't need to worry about things like downloading jars. It just handles that for you. Let it do it's job.
If you have an internal artifactory like JFrog maybe you should check that the jar is there. Do not download manually to .m2 because it's at least strange. At most you can upload the jar in that artifactory manually.
I have a proprietary library. I am using this library in my java desktop project but now, I have a maven project. I want to add this library in my maven project with dependency. How can I do this?
Firstly you should search if this library is available as maven dependency. Try maven search.
For example if you want to include a library commons-io-2.4.jar, you serach for it in the link above, if it is in public repository (it is), then you get maven dependency:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
You should paste this dependency to your pom to dependencies tag.
If above library is not available in public repository, you have to place your jar manually in your local repository by refering to: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Example:
mvn install:install-file -DgroupId=commons-io -DartifactId=commons-io -Dpackaging=jar -Dversion=2.4 -Dfile=home_folder_path/commons-io-2.4.jar -DgeneratePom=true
If it is not already on maven repository, simply add it to your pom.xml, and add it to your local repository.
<dependencies>
<dependency>
<groupId>com.proppath</groupId>
<artifactId>mylib.jar</artifactId>
<version>myjarversion</version>
</dependency>
And also put this prop library into
.m2\repository\com\proppath\myjarversion
Give any groupId you like but make sure that you have corresponding path on repository to find it.
Normally, in large projets these kind of propriatery libraries are stored in Nexus of your enterprise.