0

I need to use JARs in my maven project. But these JARs are located on hdd disc, like d:\MyJar.jar. I need use it in my project to resolve dependencies.

I know that I can install it in local maven repository, and use it. But my client doesn't want this for some reasons (scared of some licence agreements or something, it doesn't matter, he insists).

In Intellij Idea I can go to Project Structure and add libraries there, but I need to compile it from command line with - mvn package command.

So, I need to add myjar.jar to classpath without installing it in maven repository, using only maven.

How can I do this?

azurefrog
  • 10,785
  • 7
  • 42
  • 56
Max Husiv
  • 305
  • 1
  • 4
  • 12

1 Answers1

1
 System scope allow you that:

<dependencies>
    <dependency>
      <groupId>com.package</groupId>
      <artifactId>MyJar</artifactId>
      <version>1.0.0</version>
      <scope>system</scope>
      <systemPath>./lib/MyJar.jar</systemPath>
    </dependency>
  </dependencies>

https://maven.apache.org/general.html#tools-jar-dependency

  • As I understand it jar mast be in folder /com/package/1.0.0/MyJar. No? I need to resolve dependency on class in package - com.package.utils.Clasname. As I understand I need to put it in goupid/artifactid/version folder. No? But I can't move my jar. – Max Husiv Jun 26 '15 at 03:39
  • Not really, groupID and artifactID are just for maven to identify your project across many other. You can put what ever you want at groupID but the artifactID is your jar name without version. The most important is the version, scope and systemPath properties. Take a look at this link for more info about maven naming convention: https://maven.apache.org/guides/mini/guide-naming-conventions.html And you don't need to move your jar, just put at groupID something like 'com.mycompany.', at artifactID the name of you jar name, version what you want, but indicate the absolute path in systemPath – kad Dembele Jun 26 '15 at 04:01
  • I am not understanding your issue, just add the dependency one time in your project POM and it's done for all classes in this project? If you have multiple projects, create a parent POM for those projects and add your dependency to the parents POM. All will be done for you, that's one of maven goals! Or maybe, I have not definitely understood your problem – kad Dembele Jun 26 '15 at 04:52
  • Thanks. It works fine. Really appreciate it. – Max Husiv Jun 26 '15 at 04:55