Maven can not resolve dependencies from private nexus [duplicate] - java

I am trying to understand how maven downloads the binaries from the repositories.
For example, I have the following dependency for my project:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.1</version>
</dependency>
Now, these binaries are present in http://mvnrepository.com/.
In pom.xml, we have <repositories> tag where we specify the repository URL from where maven can download the files, template:
<repositories>
<repository>
<id>mvnrepository_id</id>
<name>mvnrepository.com</name>
<url></url>
</repository>
Now, my doubt is, what should be the value of the <url>; does it need to be the base url , like http://mvnrepository.com/ or the complete URL --> http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs
To me it appears that is should be the base url else for each dependency we have to put the complete URL.
Can anyone help me understand this?

Unless you want to fetch artifacts from a repository different from the default Central Maven repository, you need not add the <repositories> section to your pom.xml. Read about Maven Repositories here and here.
And the url for default Central Maven repository is http://repo.maven.apache.org/maven2/.
PS: The URLs you have posted are the ones for the Website.

Related

How does maven know which repo to use for a dependency?

First off, I searched google but cant seem to find an answer for this. Apologies if its an obvious answer.
In maven we can define 0 or more repositories where it looks for resources. Repositories can be defined in settings.xml or within your pom. By default if you define no repositories everything will come from a repository name 'central' which is just the default one maintained by maven.
The below setup pom snippet comes from the jboss eap sample apps. When I do a mvn clean install I can see some things are pulled from central and some from the jboss repos. There does not seem to be anything in the dependency tag that tells maven which repository contains the dependency so how does it decide? Is it some how tied to group ID in the dependency or does maven just check all the repos one by one till it finds the first one that contains the jar?
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.xml.bind</groupId>
<artifactId>jboss-jaxb-api_2.3_spec</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jboss-enterprise-maven-repository</id>
<url>https://maven.repository.redhat.com/qa/</url>
</repository>
<repository>
<id>jboss-enterprise-maven-repository-ea</id>
<url>https://maven.repository.redhat.com/earlyaccess/all/</url>
</repository>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
Maven just goes through the list and looks into all the repositories.
It is not possible to tie dependencies to special repositories.
Lets take a look at the official documentation:
Remote repository URLs are queried in the following
order for artifacts until one returns a valid result:
Effective settings:
Global settings.xml
User settings.xml
Local effective build POM:
Local pom.xml
Parent POMs, recursively
Super POM
Effective POMs from dependency path to the artifact.
For each of these
locations, the repositories within the profiles are queried first in
the order outlined at Introduction to build profiles.
Before downloading from a repository, mirrors configuration is
applied.
Effective settings and local build POM, with profile taken into
account, can easily be reviewed to see their repositories order with
mvn help:effective-settings and mvn help:effective-pom -Dverbose.

not able to import classes from jar which was downloaded from custom maven nexus repository

I have deployed my external jar to local Nexus repository. I have defined repository in setting.xml and provided dependency in POM.xml.
My project is able to download the jar in Maven dependencies , however When I tried to import any class from the that jar.
I am not able to import it. It is saying cannot be resolved to a type.
So in short I am not able to use the classes from jar which i have downloaded from local nexus repository.
Can any one help me here?
here is repository part of my Setting.xml file
<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>modelhelper-repo</id>
<name>Modelhelper repository</name>
<url>http://localhost:8081/#browse/browse:maven-public </url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
myprofile
here is dependency from pom.xml file:
<dependency>
<groupId>com.ravina</groupId>
<artifactId>modelhelper</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
There is Employee and other many classes in this modelhelper-1.0.0.jar, which I am not able to import in my project.
Your repository's URL in settings.xml doesn't seem to be correct - it looks like you've used the URL from your browser. The URL you should use is http://localhost:8081/repository/maven-public/
The repository URL can be found in Administration -> Repositories -> [repository_name]
Scope of the dependency is provided (means will be provided by container/parent). If you want to use the dependency during compile time. Change the scope to compile.

Unable to add IBM db2jcc4 jar file through Maven

I am trying to access DB2 tables in a java project. I am able to access the tables when I manually added the jar files - db2jcc4.jar and db2jcc_license_cisuz.jar. No issues in accessing the tables.
But when I try to add these jar files through Maven, they won't add to the project.
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>9.7.0.4</version>
</dependency>
Error Message - Missing artifact id.
Also, the latest db2jcc4.jar files (Version 11.1) are not present in Maven repository. Is there any other place I can access it from?
You have to download the right driver from IBM.
http://www-01.ibm.com/support/docview.wss?uid=swg21363866
Then install it to your local maven repository
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
As written in maven central repository the artifact is in another repo.
Add it to your pom and it will work.
<repositories>
<repository>
<id>Alfresco</id>
<name>Alfresco</name>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</repository>
</repositories>
Assuming that , using share drive is the option to go.
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>licences</artifactId>
<version>0.7</version> <!-- Adjust this properly -->
<scope>system</scope>
<systemPath>R:\JDBC drivers\IBM DB2_db2_2.2.0.v20130525_0720\db2jcc_license_cisuz.jar</systemPath>
</dependency>
According to maven central repository the artifact is in another repository. Include these two in your pom.xml and it should work:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
<repositories>
<repository>
<id>com.ibm.db2.jcc</id>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</repository>
</repositories>

JAHMM Package Maven

I need to work with be.ac.ulg.montefiore.run.jahmm package for Hidden Markov Models in java.
My project is a mevenized project so I need to use the corresponding dependency.
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
The above dependency is not being resolved in my project.
Does anyone know how to help me?
Thank you.
Your dependency is not in the Maven Central Repository.
Find out the repository used by the authors to publish their artifacts and add this repository to your POM or to your settings.xml.
If it is not published to the usual online maven repositories, you will need to install it on your local machine first.
So download the sources, go to the top level and do the usual
mvn install
Once you installed jahmm locally, your project can resolve it from your maven cache.
Adding this repository should do the trick:
<repositories>
<repository>
<id>jsi</id>
<url>http://repo.springsource.org/libs-release-remote</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
...
</dependencies>

Vaadin Maven Repo and Artifactory

I developed an java web-app application with spring and vaadin, in this application, I used some addons like easyuploads and wizards-for-vaadin. Then i added the following configuration in my pom.xml.
<dependency>
<groupId>org.vaadin.addon</groupId>
<artifactId>easyuploads</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>wizards-for-vaadin</artifactId>
<version>1.1.0</version>
</dependency>
<!-- Add-On Repository -->
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
Now I'm installing artifactory (for the first time) like tool of repository managment and I thought to add a remote repository for the vaadin-addons. But this not work:
How can I solve it ?
Is this the correct way?
Their repository is not browsable, that's why you get the 404 on testing. You can disregard the error, if should resolve the artifacts just fine (assuming the coordinates are correct).
We found out by accident that there seems to exist a browsable Nexus repository now: http://vaadin.com/nexus/content/repositories/vaadin-addons/
We have successfully included it as a proxy repository in our local Nexus installation.

Categories