2

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.

Gobliins
  • 3,848
  • 16
  • 67
  • 122
  • The Maven documentation does not give an alternative to `mvn install: file` I believe. – Tim Biegeleisen Oct 23 '15 at 08:33
  • Can this command be done out of the pom.xml ? – Gobliins Oct 23 '15 at 09:22
  • From what I was able to find, no it can't (but I may be wrong). I think Maven tends to view 3rd party JARs which are not in a central repository as rare events. So the inconvenience to you by having to manually install them into your local repo is something which won't happen too often. – Tim Biegeleisen Oct 23 '15 at 09:23
  • @TimBiegeleisen would it be possible, instead of adding jar as dependency to add the pom.xml which adds builds the jar as a dependency? – Gobliins Oct 23 '15 at 12:01

2 Answers2

3

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.

Abbel
  • 320
  • 1
  • 9
  • 1
    When i see this correctly, also in this answer i have to do the mvn:install command – Gobliins Oct 23 '15 at 09:21
  • You can just build like anywhere else with maven if you use this option. All it does is registering an extra repository, like any other repository you might use. Just be sure to name and place the jar correctly (see the naming information in my answer) – Abbel Oct 23 '15 at 09:32
  • @Gobliins I added a fully working example (i did not add the project-information since you might want to use your own), which compiles with simply running mvn clean install. I hope this is what you need – Abbel Oct 23 '15 at 09:54
  • Well thx, but the problem is still the usage of the mvn install file command to install files in the repository. It is not possible to just copy the dependecies inside the /repo path. – Gobliins Oct 23 '15 at 10:01
  • 1
    It is but you have to use the the right structure to put them there. I did not once use the mvn install file command - edit: i will head to lunch-break any moment. If this does not work for you with the setup i explained, then please give me some detailed information (the full file-path to your jar and the repo url you use (please note the missing double-slashes before my project-basedir). I will then try to solve this with you after my lunch-break (maybe an hour from now) if you cannot find the solution until then – Abbel Oct 23 '15 at 10:05
  • ok i tried it, but it didnt work, now one dependency is io.swagger swagger-models 1.5.4-SNAPSHOT And the lib is: swagger-models-1.5.4-SNAPSHOT.jar – Gobliins Oct 23 '15 at 10:49
  • and my path was /repo/io.swagger/swagger-models/swagger-models-1.5.4-SNAPSHOT – Gobliins Oct 23 '15 at 10:50
  • change your path for the directory of the jar to /repo/io/swagger/swagger-models/1.5.4-SNAPSHOT each "." in the groupId is a new directory – Abbel Oct 23 '15 at 10:57
  • ok i did it exactly like this but still the dependency is not found – Gobliins Oct 23 '15 at 11:08
  • Could please update your question with the dependency tag, the repository tag you are using now and the exact path to the file starting from the directory where your pom is? and the jar-name too – Abbel Oct 23 '15 at 11:10
  • i added the misisng structure and updated the question – Gobliins Oct 23 '15 at 11:16
  • 1
    Did you remove the two slashes at the beginning of your Repository-URL? it should be file:${project.basedir} (at least this works for me) – Abbel Oct 23 '15 at 11:25
  • ok i tried it but it is still giving me the same error i have now file:{project.basedir}/repo and repo\io\swagger\swagger-models\1.5.4-SNAPSHOT – Gobliins Oct 23 '15 at 11:54
  • 1
    In your updated question the 'J' in 'jar' is uppercase...i do not know this, but maybe this is a problem if you are on Unix based system (i am currently on Windows so this works for me). Also please always use the -U tag when building, so we can be sure that maven always tries to load the jar. If this does not work please post the full errormessage you get when running with the -X tag – Abbel Oct 23 '15 at 12:00
  • it was a type the file is .jar, i try with the parameters – Gobliins Oct 23 '15 at 12:09
  • ok with the -U it seemed really to work but i have now the noclassdeffound error when running the jar, i need to check – Gobliins Oct 23 '15 at 12:28
  • Ok, glad this works, i will edit my answer to make it more clear to following readers – Abbel Oct 23 '15 at 12:35
0

I suggest you to use system tag in your dependency tag. Hope it will work.