Adding maven local dependecies without mvn install:install-file - java

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.

Related

Maven add external jar

I would like to add the following jar
gson-extras-1.0-SNAPSHOT.jar
the jar structure is the following
looking at the manifest the version is
Manifest-Version: 1.0
the pom is the following
<repositories>
<repository>
<id>grupoicarep</id>
<url>file:///C:/stix/stix_ica/stix2/lib/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.gson</groupId>
<artifactId>typeadapters</artifactId>
<version>0.1</version>
</dependency>
but it shows the following error:
Failed to execute goal on project stix2: Could not resolve dependencies for project es.grupoica:stix2:jar:0.0.1-SNAPSHOT: Failure to find com.google.gson:typeadapters:jar:0.1 in file:///C:/stix/stix_ica/stix2/lib/ was cached in the local repository, resolution will not be reattempted until the update interval of grupoicarep has elapsed or updates are forced -> [Help 1]
[ERROR]
I have tried many combinations but I am just guessing and not getting the right result
I donĀ“t know what I am doing wrong
many thanks in advance
Ana
Use below dependency to include the jar available in the local machine to maven.
<dependency>
<groupId>groupid</groupId>
<artifactId>artifactid</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}\lib\JAR_NAME.jar</systemPath>
</dependency>

How do I include a maven package that has invalid/outdated POM?

I want to use a package named sourcemap in my project. It's not available in maven central, but in Atlassian's public maven repository. I therefore set up my pom.xml like this:
<repositories>
<repository>
<id>atlassian</id>
<name>Atlassian</name>
<url>https://packages.atlassian.com/content/repositories/atlassian-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.atlassian.sourcemap</groupId>
<artifactId>sourcemap</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
Now, the POM file for sourcemap references another POM file from a package named public-pom:
<!-- POM for sourcemap (NOT my pom.xml!) -->
<parent>
<groupId>com.atlassian.pom</groupId>
<artifactId>public-pom</artifactId>
<version>3.0.84</version>
</parent>
The problem: the POM file references version 3.0.84 of public-pom, but Atlassian's repo no longer provides 3.0.84. Currently, the oldest available version of public-pom is 5.0.0, as you can see here. Because of this, maven complains when I attempt to build the project:
Could not find artifact com.atlassian.pom:public-pom:pom:3.0.84 in atlassian (https://packages.atlassian.com/content/repositories/atlassian-public/)
How can I fix the POM and use this package in my project?
Mvnrepository lists com.atlassian.pom:public-pom:pom:3.0.84 but when selecting the link to it:
status: 404
message: "Could not find resource"

Adding external jar to maven repository not working [duplicate]

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>

Download JFXtras 8.0-r5 or 8.0-r6

I am trying to download the latest build of JFXtras (i want the .jar file) but i can't find it.
For 8.0-r6 i can see some .jar.soc .jar.asc what are those files? https://oss.sonatype.org/content/repositories/snapshots/org/jfxtras/jfxtras-all/
For 8.0-r5 a jar exists but it is empty it has only Meta-Inf http://central.maven.org/maven2/org/jfxtras/jfxtras-all/
How to download the jar or build it?And what are those other files there?I haven't seen them again that's why i am asking..
Problem Converting Project to Maven:
The .jar.asc files contain a PGP signature.
To make maven download the jar from maven central, add the dependency to pom.xml, e.g.
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-all</artifactId>
<version>8.0-r5</version>
</dependency>
</dependencies>
Or grab the jars manually from http://central.maven.org/maven2/org/jfxtras/ and add them to your project.
If you want to use the bleeding edge snapshot (currently 8.0r6-SNAPSHOT), you'll need to add the sonatype repository to your pom like
<repositories>
<repository>
<id>snapshots-repo</id>
<name>Sonatype Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
And add the current snapshot to the dependencies, e.g.
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-all</artifactId>
<version>8.0-r6-SNAPSHOT</version>
</dependency>
</dependencies>
But be aware that they're development versions (unstable), and their availability in that location can be temporary.
To download the -SNAPSHOT jars manually, you go to the sonata snapshot repository, choose the jfxtras package that you want to download, and scroll down to find the jar. They're simply not keeping all the older snapshots.

Import and use a class from a jar using Maven

I am trying to implement hoptoad in my existing maven project. I ve given the following lines in pom.xml as suggested in http://code.google.com/p/hoptoad/
<project>
<repositories>
<repository>
<id>hoptoad-repository</id>
<name>Hoptoad Repository</name>
<url>http://hoptoad.googlecode.com/svn/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>code.lucamarrocco</groupId>
<artifactId>hoptoad-notifier</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</project>
When i try to use the HoptoadNotice in my catch block, i m getting ClassNotFoundException. I am using Eclipse IDE. I am not able to figure out, that the problem is because of inclusion of this code(in pom) or in the IDE. I can understand that the inclusion of these lines alone do not help the code to recognize the jar. So, i tried installing the jar in maven repository. But still it did not help.
Note:- I have not just blindly copied as shown above, directly into the pom.xml. I have included the lines of code wrt <dependencies> and <repositories> blocks.
The maven configuration looks correct.
Make sure that the hoptoad-notifier-1.8.jar is correct deployed.
For an standalone app, this means for example specified in the argument list or the manifiest.
For an web app, it means the jar is copied (by maven, not by you) in the libs folder.

Categories

Resources