7

I have a Project called Parent. Its type is POM. There is a library (ojdbc6.jar) that is not available in public repository so I am accessing it via <SystemPath> as you can see in below pom.xml:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.Parent</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>childModule</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>6</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>in-project</id>
            <name>In Project Repo</name>
            <url>file://${basedir}/lib</url>
        </repository>
    </repositories>

Now the child project names are Child-Module1 and Child-Module2 use this (ojdbc6.jar) library It's POM is mentioned below:

<project>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>testApp</artifactId>
    <version>1.14.5.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>APP1</name>
    <description>Application</description>

    <parent>
        <groupId>com.Parent</groupId>
        <artifactId>Parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
</project>

When I build using Maven it gives me error:

Description Resource    Path    Location    Type
The container 'Maven Dependencies' references non existing library
'C:\Users\ABCCOMPUTER_NAME\.m2\repository\com\oracle\ojdbc\6\ojdbc-6.jar'
testApp Build path Problem.

Why does it looks in local repository? It happen only when parent project contains a library (jar) that contains system path. It does not happen when access system path library (jar) in same project, like parent referring ojdbc6.jar, it is fine there.

Johnny Martin
  • 355
  • 5
  • 16
  • Where is the jar located relative to the children? The basedir property is different value in the parent and children. – Jose Martinez Oct 23 '15 at 18:55
  • Jar is located in lib folder relative to parent project and maven trasfer the dependency jars to its module.I assume maven convert relative to absolute path when its include dependency jar to child module. – Johnny Martin Oct 24 '15 at 05:25

2 Answers2

5

I resolved the issue by updating systemPath in parent pom.xml as shown below :

 <systemPath>${main.basedir}/lib/ojdbc6.jar</systemPath>

and then adding the main.basedir property in parent pom.xml and repository

<properties>
        <main.basedir>${project.basedir}</main.basedir>
    </properties>
<repositories>
        <repository>
            <id>in-project</id>
            <name>In Project Repo</name>
            <url>file://${main.basedir}/lib</url>
        </repository>
</repositories>

then adding below properties and repositories element in child module(The "/.." is added as the child module folder reside in parent folder so go up one directory then rest absolute path to parent lib folder shall be generated as expected):

  <properties>
        <main.basedir>${project.basedir}/..</main.basedir>
    </properties>
<repositories>
            <repository>
                <id>in-project</id>
                <name>In Project Repo</name>
                <url>file://${main.basedir}/lib</url>
            </repository>
    </repositories>
Johnny Martin
  • 355
  • 5
  • 16
  • [This answer](http://stackoverflow.com/questions/1012402/maven2-property-that-indicates-the-parent-directory) help me to figure out the issue but its answer did not solve my problem so i did some R&D and come up with the solution metnioned above. – Johnny Martin Oct 26 '15 at 10:07
  • thanks for providing easy way-around of problem. +1 – Chaitan Yadav Sep 17 '20 at 06:11
0

From: https://stackoverflow.com/a/2230464/1490322

Finally, declare it like any other dependency (but without the system scope):

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>3rdparty</artifactId>
  <version>X.Y.Z</version>
</dependency>
Community
  • 1
  • 1
Jose Martinez
  • 9,918
  • 6
  • 41
  • 60
  • 1
    The answer you have mentioned has a drawback i wonder why people appreciating it.When you commit the project to any i.e. SVN repository so that other developers can get and accesss the project etc. They need to run the command svn install bla bla ..(inorder to commit in there local repo) and if there are many non-global-repo jar then it is time consuming task. – Johnny Martin Oct 24 '15 at 05:35
  • This doesn't work with multi-module builds, and the OP's question already implies some understanding of this strategy – Trevor Brown Jun 08 '16 at 22:08