Adding external jar to maven repository not working [duplicate] - java

This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 2 years ago.
I've installed my jar in my local repo as said in maven docs :
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<dans>
-DartifactId=<dans-lib>
-Dversion=<1.0.0>
-Dpackaging=<jar>
-DgeneratePom=true
I can see in my /home/.m2/repository that the location is created and in the dans/dans-lib/1.0.0 there is my jar file.
Unfortunately when I'm trying to add maven dependency in my pom.xml
<dependency>
<groupId>dans</groupId
<artifactId>dans-lib</artifactId>
<version>1.0.0</version>
</dependency>
I got error Dependency dans:dans-lib not found. I've got no idea what might be the problem

First solution is to add local repo to pom.xml something like this
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
</repository>
</repositories>
2nd solution woudld be to load jar file
<dependency>
<groupId>dans</groupId
<artifactId>dans-lib</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

Related

Maven artifact not found in central [duplicate]

This question already has answers here:
Maven Could not resolve dependencies, artifacts could not be resolved
(17 answers)
Closed 6 months ago.
I'm trying to use this Maven dependency for a project https://mvnrepository.com/artifact/org.eclipse.ecf.protocol/bittorrent/0.3.0
I used the declaration in my pom.xml, when I update the project it could not resolve dependency from this https://repo.maven.apache.org/maven2/ URL.
So I looked up the page and there was no Bittorent jar there. Can anyone explain me why this jar is missing from the maven2 repo and how to resolve this error. I tried other answers but nothing works for this one.
There are other ways for an author to host their jars in their public website. But I'm not sure why dependency resolving error occurs in this repo, when I figure out I'll edit this answer to include it.
Until then You can download the jar from files section of the repository page and include it in your class path to solve this issue for now.
here's the link to file
This artifact is not hosted on the maven central repository (https://repo.maven.apache.org/maven2/), but rather on: https://www.jabylon.org/maven/
You can double-check this by navigating to: https://mvnrepository.com/artifact/org.eclipse.ecf.protocol/bittorrent
In your case, the solution is to add the repository to your pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.eclipse.ecf.protocol</groupId>
<artifactId>bittorrent</artifactId>
<version>0.3.0</version>
</dependency>
<!-- ... -->
</dependencies>
<repositories>
<repository>
<id>Jabylon</id>
<url>https://www.jabylon.org/maven/</url>
</repository>
</repositories>
</project>

Adding maven local dependecies without mvn install:install-file

I have some local jar files in a folder /src/main/resources/foobar under my basepath.
I have them included as dependencies in my POM.xml:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.4-SNAPSHOT</version>
</dependency>
Now i tried to add them with a local repository:
<repositories>
<repository>
<id>resource-repository</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
Now still i get the error message that the jars inside this reposirtory not found:
The following artifacts could not be resolved: bar... in file://.../repo was cached in the local repository, resolution will not be reattempted until the update interval of resource-repository has elapsed or updates are forced -> [Help 1]
I have not used the
mvn install:install-file
command for this. And i would be happy if there is a solution where i dont need to do this.
Edit:
The folder structure is:
repo\io\swagger\swagger-models\1.5.4-SNAPSHOT
and Jar inside:
swagger-models-1.5.4-SNAPSHOT.Jar
Funny though i get a warning about a missing POM from this file when running maven install.
You can declare a Repository for your third party dependencies.
The dependencies must be placed inside the repoBase path and the directory for the jar must follow the pattern: "{groupId}/{artifactId}/{artifactVersion}". Inside this folder the jar has to be named "{artifactId}-{artifactVersion}.jar".
Example:
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>resource-repository</id>
<url>file:${project.basedir}/repo</url>
</repository>
I have this in my pom (and of course the project-tag and group-id etc.)
I then have a directory repo in my project-directory.
In the path "repo\foo\bar\1.0" i then have a "bar-1.0.jar" file inside this directory. This compiles for me (ok, the jar is empty but this does not matter for an example).
Please note that the url for the repository does not contain the two slashes after the "file:".
I hope this example is a little bit more understandable for anyone who tries to this.
I suggest you to use system tag in your dependency tag. Hope it will work.

How to include remote jar dependency in Maven

I need to include a third party jar to my pom.xml (using Maven 3.2.5 on a Linux environment).
If the jar file is available on the same machine that runs the build I can just declare the dependency in this way:
<dependencies>
<dependency>
<groupId>Foo</groupId>
<artifactId>Foo</artifactId>
<version>Foo-1.0</version>
<scope>system</scope>
<systemPath>/myspace/javalibs/foo-1.0.jar</systemPath>
</dependency>
</dependencies>
But what if the jar is on a different server such as
<repositories>
<repository>
<id>myrepo</id>
<url>http://192.168.0.14/download/java/thirdparty_repo</url>
</repository>
</repositories>
In what element should I specify the name of the jar file?
Remove
<scope>system</scope>
<systemPath>/myspace/javalibs/foo-1.0.jar</systemPath>
from pom and Maven will find the jar in http://192.168.0.14/download/java/maven_repo automatically

How to put own jar to project(non local) repository? [duplicate]

This question already has answers here:
how to deploy my artifact on to my nexus?
(4 answers)
Closed 8 years ago.
I have a jar file with source code. Our project has own Nexus repository. I want load this file to into this repository and get dependency tag for download it.
Can you describe the procedure ?
I want to write line in cmd
You have to add a dependencies tag in your pom.xml :
<dependencies>
<dependency>
<groupId>org.yourgroupid</groupId>
<artifactId>your-artifact-id</artifactId>
<version>your-version</version>
</dependency>
</dependencies>
And you have to add a repositories tag on which you will put your repository URL:
<repositories>
<repository>
<id>your-id</id>
<url>http://your-url</url>
</repository>
</repositories
Edit
Here is the way to deploy to your Nexus:
<distributionManagement>
<repository>
<id>nexus-repo</id>
<url>http://your-nexus</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://your-nexus</url>
</snapshotRepository>
</distributionManagement>
It can use scp or you may need to add wagon-plugin or cargo-plugin.
See more: http://maven.apache.org/pom.html#Distribution_Management

Loading Maven dependencies from GitHub [duplicate]

This question already has answers here:
Can I use a GitHub project directly in Maven?
(3 answers)
Closed 2 years ago.
How do I add a Java library from its GitHub repo (the library uses Maven as a build system) as a dependency to my Maven project? Can I do that without downloading and compiling the library?
Now you can import a Java library from a GitHub repo using JitPack.
In your pom.xml:
Add repository:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Add dependency
<dependency>
<groupId>com.github.User</groupId>
<artifactId>Repo name</artifactId>
<version>Release tag</version>
</dependency>
It works because JitPack will check out the code and build it. So you'll end up downloading the jar.
If the project doesn't have a GitHub release then its possible to use a commit id as the version.
At the moment there is no way you can do this unless the maintainer of the library provided a way to do this.
So on the title page of the library the should be an instruction containing the repository address like:
<repositories>
<repository>
<id>YOUR-PROJECT-NAME-mvn-repo</id>
<url>https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
And a dependency name:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
</dependency>
This means that all artifact of your project including your dependency will be searched in this repo.
You could also have a glance at pom.xml to check if there was an effort made to deploy artifacts to a remote repo. Typically the keywords are oss.sonatype.org or raw.github.com like in this case.
FYI, here is a way to provide a repo for your gihub artifact: Hosting a Maven repository on github.
Github now supports packages https://help.github.com/en/github/managing-packages-with-github-packages/configuring-apache-maven-for-use-with-github-packages
You can follow the steps above to deploy Jar files to github properly.
Another very nice thing about Jitpack is, it has a lookup button on the main page. And if you type the URL of your GitHub repository, it displays different commits of the source code, and you can select which commit/tag you want. The Jitpack creates pom dependencies for you.
It became dead simple.

Categories

Resources