2

Is it possible to have a dependency on a project that is only on my local machine and not in any repository?

If so, how do I specify it in my POM, would I use the following format below?

 <dependency>
    <groupId></groupId>
    <artifactId></artifactId>
    <version></version>
</dependency>
Hugo y
  • 1,263
  • 9
  • 19
java123999
  • 5,574
  • 28
  • 66
  • 104
  • 1
    You need to install the dependency in your local Maven repo; there should be plenty of questions/tutorials/material about how to do that...it's pretty straightforward – x80486 Mar 30 '16 at 14:25
  • ok, is it just a case of using the "mvn install" command? – java123999 Mar 30 '16 at 14:27

2 Answers2

2

Install that dependency to your local maven repository using mvn install. Then your local projects can use it as a dependency. Of course that will only work on that one machine.

If you use Eclipse/NetBeans/IntelliJ and have the dependency as well as the project using that dependency opened, you don't need to install it as those IDEs resolve this without involving the local maven repo.

If your dependency is not a maven project, you simply have to reference the jar file. Or you assign artifactId and groupId and install the jar file to your repo.

Both ways are shown here.

f1sh
  • 9,331
  • 3
  • 22
  • 47
  • Thank you, can you please give an example of how I would declare it in my Parent and Child POMS in my current project that will use it as a dependency? – java123999 Mar 30 '16 at 14:28
  • If your dependency is a maven artifact, it has a ``groupId`` and ``artifactId``. That's all you need to reference it. – f1sh Mar 30 '16 at 14:30
  • ok, even if it is only a local project? How can I find the groupId and artifactId? I am new to Maven, appreciate the help – java123999 Mar 30 '16 at 14:32
  • Updated my answer. – f1sh Mar 30 '16 at 14:36
1

install the dependency using mvn install like take a example of oracle ojdbc6 or ojdbc14 jar we cannot find this jar in central or remode repository so to use this we need to install this jar in maven local repository

Syntax:-

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

example:-

mvn install:install-file -Dfile=C:/oraclexe/app/oracle/product/11.2.0/server/jdbc/lib/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

note:- Cmd should be opened in location of jar only i.e- mvn install:install-file command must run at jar location only

Configuring POM.XML(in program)

<!-- ORACLE database driver -->
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
</dependency>

note:- even one project developed in maven can be added as jar in another

Anurag
  • 21
  • 2