0

I am trying to get a third party library to work in my application. It has one main jar file, core.jar. It is not available through Maven's online repository which is how we normally include third party libraries. We already have a local repository set up for maven:

<repository>
        <id>project.local</id>
        <name>Local Project Repo</name>
        <url>file:${project.basedir}/local-repo</url>
    </repository>

And the project is recognizing core.jar that I have put in the local-repo folder (along with a pom file). I can call methods from it, etc. My issue is that I was provided the core.jar file along with many other jars that are apparently dependencies of core.jar. I cannot figure out how, if it is even possible, to get core.jar that I imported through the local-repo to recognize it's dependencies. Right now they are all sitting in the same folder as core.jar, but it is throwing errors saying that classes do not exist. I tried to edit the pom.xml file for core.jar and add some dependencies there, but it does not seem to be working.

I have done a lot of googling around in the last few days but I have not been able to find any answers for how to do this. Maybe I am blind. Is it even possible to make this work in this way?

  • Possible duplicate [How to add local jar files to a Maven project?](https://stackoverflow.com/questions/4955635/how-to-add-local-jar-files-to-a-maven-project) – MadProgrammer Jul 21 '22 at 22:21
  • You may want to try this in a path with spaces. – Thorbjørn Ravn Andersen Jul 21 '22 at 22:22
  • @MadProgrammer I did look at that question. As far as I can tell, that is about importing one jar to Maven. I have done that. The issue is that one jar has dependencies on other jars, and I cannot figure out how to make my new jar able to recognize it's dependencies. I have tried some of the suggestions in that question and I could not get any of them to work. – erwang24 Jul 21 '22 at 22:39
  • @ThorbjørnRavnAndersen I am not sure what you mean. Are you referring to the /local-repo path? – erwang24 Jul 21 '22 at 22:39
  • @erwang24 Then you will manually need to import the dependencies the same way – MadProgrammer Jul 21 '22 at 22:46
  • @erwang24 You are putting a file name inside something that is a URL. That will not always work. Try moving to a folder with a space in its name. – Thorbjørn Ravn Andersen Jul 22 '22 at 01:57
  • I think you need to elaborate on what exactly this means: "I tried to edit the pom.xml file for core.jar and add some dependencies there, but it does not seem to be working" - what is the name of the pom file (it has to be core-version.pom.xml I think), what exactly did you add, and how exactly does it "not work". Adding dependencies to this core pom file is the correct thing to do, IMO. – Jelaby Jul 22 '22 at 06:51
  • Does the Pom you created for the jar list the dependencies? – Thorbjørn Ravn Andersen Jul 23 '22 at 08:58

1 Answers1

0

The best approach is to set up a Maven .mirror for the use of all developers. A tool like Nexus is designed to do this. Release your core jar to this mirror (or just copy it into the correct place in the repository file system). Then you can include your core jar in the same way that you include third party jars in your projects. Maven will automatically load any third party dependencies specified in your core jar's pom.xml.

kiwiron
  • 1,677
  • 11
  • 17