0

I am working on Maven project and I have a jar app-client.jar which have dependency on app-core.jar. So I have a pom.xml for app-client.jar and that pom.xml has dependency of app-core so we added dependency of app-core in this pom.xml. Now I wanna use the app-client.jar in my main project. Because this jar is build locally and not available at remote repository. So I did add the app-client and also specify the location repository where it will located. as following..

<repositories>
   <repository>
       <id>repo</id>
       <releases>
           <enabled>true</enabled>
           <checksumPolicy>ignore</checksumPolicy>
       </releases>
       <snapshots>
           <enabled>false</enabled>
       </snapshots>
       <url>file://${project.basedir}/../lib</url>
   </repository>
<repositories>
<dependencies>
   <dependency>
       <groupId>com.sample</groupId>
       <artifactId>app-client</artifactId>
       <version>1.0</version>
   </dependency>
</dependencies>

and also I put my jar as following [My Module] / [com] / [sample] /[app-client] /[1.0]/app-client-1.0.jar

When I run mvn clean install I got error app-client's pom.xml not found. and build get failed. Usually when I use single jar then its working fine, but if I use jar having dependency with other jar it getting failed.

So how can I build my app-client jar and their pom so that it behave normal and also deploy app-core.jar too.

Tej Kiran
  • 2,218
  • 5
  • 21
  • 42
  • Same question was answered here: https://stackoverflow.com/a/22300875/7339164 –  Oct 17 '18 at 05:29

2 Answers2

1

firstly when you are building app-client.jar build a fat jar which includes app-core.jar dependency.

Next copying app-client-1.0.jar into the specified location of local repo doesn't work, to add this jar into your local repo use this command mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>.

  • In my project I have lots of dependencies, so I don't want to add list in the given command. Second if I add app-core.jar dependency in my project's pom then also its working fine. But it should be deploy automatically for app-client.jar. – Tej Kiran Oct 17 '18 at 05:39
  • to deploy app-core with app-client build a fat jar. – Arunmozhi Nambi Oct 17 '18 at 06:13
  • One should avoid to use fat jars as dependencies. Fat jars are purely for creating stand-alone applications. – J Fabian Meier Oct 17 '18 at 06:53
0

If you build app-client.jar with mvn clean install, then it will be installed into your Maven local repository (.../.m2/repository). Then any other project on the same computer can reference it in its pom without further information. So no <repositories> entry necessary.

If you want to work with multiple people on the same project, use a Nexus/Artifactory server to share the jars.

Solutions with lib folders and system paths are deprecated and cause trouble.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Hi, sorry for late reply and thanks for update. In my case app-client.jar and app-core.jar is provided by someone else, I am not building it on my machine. In that case what should I do? By adding that jar in .m2 folder will solve my problem? – Tej Kiran Oct 17 '18 at 15:17
  • You can use `mvn install:install-file` to install the jars locally in your Maven local repository. Better would be to check out the projects yourself and build them. Even better would be using a repository manager like Nexus/Artifactory (if the other artifacts come from somebody else on your development team). – J Fabian Meier Oct 17 '18 at 18:11