Maven doesn't find an existing remote artifact - maven

I'm trying to use docker-compose-rule to run docker-compose files in junit integration tests.
I use the following dependency in my pom.xml file:
<dependency>
<groupId>com.palantir.docker.compose</groupId>
<artifactId>docker-compose-rule-core</artifactId>
<version>0.32.0</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/com.palantir.docker.compose/docker-compose-rule-junit4 -->
<dependency>
<groupId>com.palantir.docker.compose</groupId>
<artifactId>docker-compose-rule-junit4</artifactId>
<version>0.32.0</version>
</dependency>
but for some reason the artifact is not found by maven (for none of the available versions).
As far as I can say, the artifact is found in the jcenter as shows in bintray.
It also exists on maven repository.
Can someone please tell why can't I use these libraries?
Alternatively, can I reference maven to take the library from a specific url with a specific jar file, for example from github, or from here?

According to mvnrepository, the jar you are looking for is not in the maven default Central repository, but is in the Palantir repository. You can add
<repositories>
<repository>
<id>Palantir</id>
<url>https://dl.bintray.com/palantir/releases/</url>
</repository>
</repositories>
into your pom.xml, and try again.

Related

In a Springboot Maven project, how to reference from another Jar?

I have a SpringBoot Maven project. I am dependent on another set of libraries. Currently am pointing to their repository path , downloading it to .m2 repository and using.
But the repository website is not reliable. SO I wanted to package the dependent libraries as part of JAR in the resources folder.
After putting the jars in resource folder. How can I get references of the Types/libraries ?
Currently:
<dependencies>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-core</artifactId>
<version>5.23.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>www.dcm4che.org</id>
<name>dcm4che Repository</name>
<url>https://www.dcm4che.org/maven2</url>
</repository>
</repositories>
You can put all your libraries in a single folder either in your project or in some folder in your local. You can then add them to your maven POM.
Lets say you put all your jars in a folder called libs in your base project directory. You can then add something similar to the below in your maven POM.
<groupId>com.abc.xyz</groupId>
<artifactId>my-artifact-id</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/libs/my-jar-name.jar</systemPath>
You need to use the scope system. Excerpt from Maven website,
Scope : system - This scope is similar to provided except that you
have to provide the JAR which contains it explicitly. The artifact is
always available and is not looked up in a repository.
Maven Documentation
If you read further, it also mentions that this has been deprecated. So, its a nice quickfix or a hack but then the best thing would be to set up a repository manager as suggested by others.

Specifying the maven repository URL for getting the dependencies resolved?

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.

Adding db2 jars to java webapp using maven

I'm trying to add the following db2 jars to my Java web application using Maven...
db2jcc_license_cu.jar
db2jcc_javax.jar
db2jcc.jar
I'm following the instructions posted in this post...
Can I add jars to maven 2 build classpath without installing them?
I want to use the static in-project repository solution. So far I have...
Created a folder in my root directory named lib. Inside this
directory lives the three db2 jars.
Added the following to my pom file...
<repository>
<id>lib</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>3.8.47</version>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc_license_cu</artifactId>
<version>3.8.47</version>
</dependency>
But when I run a maven install I get ...
[WARNING] The POM for com.ibm.db2.jcc:db2jcc:jar:3.8.47 is missing, no dependency information available
[WARNING] The POM for com.ibm.db2.jcc:db2jcc_license_cu:jar:3.8.47 is missing, no dependency information available
I got the version of the Jars by running a...
java com.ibm.db2.jcc.DB2Jcc -version
Have I specified this version info corretly? Can anyone suggest what I am doing wrong?
The problem is that you didn't install the jars properly in your "project-maven-repository" (i.e. in the folder ${project.basedir}/lib)
Maven stores (when you do mvn install) the jar files in a maven repository. A maven repository have precise hierarchical structure. Here is a simplified vision of this structure:
the artifact groupId+artifactId define the first part of folder path (in the repository) where the artifact is stored.
the artifact version is the second part of the folder path
the artifact version is also a suffix to the artifact name
the artifactId is the artifact name
the packaging is the artifact extension (default is jar)
By default maven use a repository located under <USER_HOME>/.m2/repository
The solution you are trying to setup use another location for the repository : ${project.basedir}/lib and even if it is not the default repository location it is still a maven-repository and so maven is expecting to find the usual maven repository hierarchy under this location.
That's why you need to organize your ${project.basedir}/lib folder just like a maven repository. That's explained in this part of the referenced post:
Use Maven to install to project repo
Instead of creating this structure by hand I recommend to use a Maven plugin to install your jars as artifacts. So, to install an artifact to an in-project repository under repo folder execute:
mvn install:install-file -DlocalRepositoryPath=lib -DcreateChecksum=true -Dpackaging=jar -Dfile=[your-jar] -DgroupId=[...] -DartifactId=[...] -Dversion=[...]
If you'll choose this approach you'll be able to simplify the repository declaration in pom to:
<repository>
<id>repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
So you need to do an mvn install to create the ${project.basedir}/lib hierarchy (you can do it by hand, but it's not recommended and error prone).
I your case, the commands to run will be like this: (assuming you put the jar in your HOME_DIR and run this command in your ${project.basedir})
mvn install:install-file -DlocalRepositoryPath=lib -DcreateChecksum=true -Dpackaging=jar -Dfile=<USER_HOME>/db2jcc_license_cu.jar -DgroupId=com.ibm.db2.jcc -DartifactId=db2jcc_license_cu -Dversion=3.8.47
What are the advantages of the approch you choose :
a developer with no maven setup will have the libraries available inside the project sources, under SCM system.
you can easily reference jars that aren't in a public maven repository without the need of something like artifactory or nexus
The drawbacks :
a quite complex folder structure under ${project.basedir}/lib looking very strange for someone not used to work with maven.
you will store the libraries under SCM (lot's of huge binary files)
Another solution would be to download those jars before hand and put them somewhere relatively to your project (like lib directory). Now just tell maven to use those jars. Here the groupId, artifactdId and version are JFYI since they won't be used to download anything.
The merit of this solution is that you won't have to build a maven repository.
<dependencies>
...
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>licences</artifactId>
<version>1.0</version> <!-- Adjust this properly -->
<scope>system</scope>
<systemPath>${basedir}/lib/db2jcc_license_cu.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>1.0</version> <!-- Adjust this properly -->
<scope>system</scope>
<systemPath>${basedir}/lib/db2jcc4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc_javax</artifactId>
<version>1.0</version> <!-- Adjust this properly -->
<scope>system</scope>
<systemPath>${basedir}/lib/db2jcc_javax.jar</systemPath>
</dependency>
</dependencies>
Refer Link (Japanese): Mavenリポジトリで提供されていないサードパーティJarをどうするか
I guess these jars do not have a pom.xml. Hence the warning. If the jars get packaged and the application works, then I guess you do not have a problem.

Should I write repositories in my pom.xml?

I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?
For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.
So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing., for all dependency tag in pom.xml
Is this because of repositories absence?
Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?
UPDATE 1
It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html
I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?
Apparently your Hibernate dependency is missing <version> tag:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version> <!-- this line is missing -->
</dependency>
Note that you don't have to specify version of dependencies previously declared in <dependencyManagement>.
Old answer:
Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every pom.xml inherits from, already defines main Maven central repository:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
You don't have to define this repository, and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to pom.xml, so that every developer is always able to build.
The bottom line is: if you can build the project having a completely empty repository, your pom.xml is fine.
It's not advisable to define repositories in POM files as that causes a lot of issues (Maven will search those repositories for ANY artifact even the ones available at Central, poor portability, ...)
Best approach: Setup a repository manager (Artifactory, Nexus) and edit your settings.xml file to use the repo manager as a mirror.
Second best approach: Define the required repositories in your settings.xml file, not in your pom.xml files.
Repositories in poms is a bad idea.

Maven can't resolve the dependency it just found

Maven must be losing its mind.
I added a dependency using Netbeans Add Dependency dialog. I searched for jax-rs-ri. It updated the index from central and showed several versions of jax-rs-ri. I selected 1.9.1 and it added this to the pom.xml:
<dependency>
<groupId>com.sun.jersey.ri</groupId>
<artifactId>jax-rs-ri</artifactId>
<version>1.9.1</version>
</dependency>
Looks right, but when I build I get the following error:
Failed to execute goal on project reply-to.test-web:
Could not resolve dependencies for project jms:reply-to.test-web:war:1.0-SNAPSHOT:
Could not find artifact com.sun.jersey.ri:jax-rs-ri:jar:1.10-b03 in
central (http://repo1.maven.org/maven2) -> [Help 1]
I've also tried changing the repository the following with the same results:
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
</repositories>
This was working earlier today. Did something just get broken with Maven?
In these cases it's worth to check the local repository (usually c:\Users\<username>\.m2\repository\com\sun\jersey\ri\jax-rs-ri or /home/<username>/.m2/repository/com/sun/jersey/jax-rs-ri) and Central:
http://search.maven.org/#artifactdetails|com.sun.jersey.ri|jax-rs-ri|1.9.1|pom
(The important part now is the "Available Downloads" table.)
So, there isn't any jar file just a zip (and the POM). You should use <type>zip</type> in your dependency like this:
<dependency>
<groupId>com.sun.jersey.ri</groupId>
<artifactId>jax-rs-ri</artifactId>
<version>1.9.1</version>
<type>zip</type>
</dependency>
Since it's a zip maybe you want to unpack it. This answer could help: Unzip dependency in maven
Please note that 1.9.1 is not the latest jax-rs-ri version and your Maven uses 1.10-b03. If you want to force it to use 1.9.1 you have to use <version>[1.9.1]</version> inside the dependency tag.

Resources