1

I got Java module and structure looks like:

moduleX
  -resources
   |-icons
     |_ icon.png
   |-libs
     |_ library.jar
  -src
pom.xml

resources is a folder mark as Resources Root in Intellij IDEA.

How should looks Maven dependency to get the library.jar ?

I tried as

<dependency>
    <groupId>library</groupId>
    <artifactId>library</artifactId>
    <version1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/resources/libs/library.jar</systemPath>
</dependency>

On OS X system works well but on Windows system do not work - do not find path.

Also I have set up a resources in pom.xml

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>resources</directory>
        </resource>
    </resources>
</build>
ACz
  • 527
  • 4
  • 18
  • Possible duplicate of [How to add local jar files in maven project?](http://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-in-maven-project) – Tunaki Feb 06 '17 at 16:07
  • Don't use `system`. Use the other answers in the linked question. – Tunaki Feb 06 '17 at 16:07
  • @Tunaki without `system` maven do not want to build it. – ACz Feb 06 '17 at 16:11
  • 1
    There are other, better, and more supported, solutions. Install the file in your local repository with `mvn install:install-file`; or use a repository manager. – Tunaki Feb 06 '17 at 16:12
  • Maybe other what without install in local repository ? I checked solutions from there but I do not find correct answer for my problem – ACz Feb 06 '17 at 16:30
  • That _is_ the solution. Or you can use a file based repository, as shown here http://stackoverflow.com/a/28762617/1743880. – Tunaki Feb 06 '17 at 16:33
  • Can You create example attached to my module structure ? – ACz Feb 06 '17 at 17:29

1 Answers1

0

I utilize this approach on my project:

  1. Create a repo folder under project:
    This folder is not necessarily marked as Resources root.

  2. run maven command to install the jar file to local repo:

mvn install:install-file -Dfile=[path to jar]/library.jar  -DlocalRepositoryPath=[path to repo]/repo/ -DgroupId=com.example -DartifactId=TestLibrary -Dpackaging=jar -Dversion=1.0
  1. Let maven recognize local repo:
<repositories>
    <repository>
        <id>my-local-repo</id>
        <url>file://${basedir}/../repo</url>
    </repository>
</repositories>
  1. Reference in pom.xml:
<dependency>
    <groupId>com.example</groupId>
    <artifactId>TestLibrary</artifactId>
    <version>1.0</version>
</dependency>
Khoa Bui
  • 653
  • 7
  • 14