18

I have a library consisting of 4 jars:

matlabcontrol-4.1.0.jar
matlabcontrol-4.1.0-javadoc.jar
matlabcontrol-4.1.0-sources.jar
matlabcontrol-demo-4.1.0.jar

How do I add them to the local repository so that Maven knows where sources are and where javadoc is?

Documentation here http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html is very brief and does not answer this question.

Pang
  • 9,564
  • 146
  • 81
  • 122
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

2 Answers2

31

The documentation clearly mentioned the way. Think your matlabcontrol-4.1.0.jar in C:> location. So move your cmd on C:> location and run following command.

mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar -DgroupId=org.matlabcontrol \
    -DartifactId=matlabcontrol -Dversion=4.1.0 -Dpackaging=jar

If you do that, you can access your jar file with dependency, like:

 <dependency>
        <groupId>org.matlabcontrol</groupId>
        <artifactId>matlabcontrol</artifactId>
        <version>4.1.0</version>
 </dependency>
Masudul
  • 21,823
  • 5
  • 43
  • 58
  • 1
    what is the purpose of groupid and artifactid ? – Timeless Jan 15 '15 at 01:57
  • @Masud I install the jar using same procedure and I can see the latest jar in my local maven repository but new jar is not reflecting in maven project...can u suggest something to me – dom Sep 18 '16 at 06:44
  • @Timeless The groupId and artefactId are what maven use to find what library you want (Sort of it like the name of a class and its package, but for jar). Roughly speaking, the groupdId identify the project the artefact is part of. When importing a custom jar, you make one up. You can use the website of the organization, for example com.mathwork.matlab, or you can use a Java package name inside the jar, like org.matlab.control. Whatever you choose doesn't matter much, as long as its unique. – Laurent Bourgault-Roy Apr 25 '17 at 17:33
  • 1
    You might also want to add the pom with '-DpomFile= – Bill Comer Jun 13 '17 at 18:42
6

Classifiers can also be specified at the command-line. See http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#classifier.

Javadoc and sources are just artifacts with a classifier of the same pom.

For example:

Install the main artifact

mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar 
   -DgroupId=matlab -DartifactId=matlab -Dversion=4.1.0

Install the javadoc using the classifier javadoc:

 mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar 
   -DgroupId=matlab -DartifactId=matlab -Dversion=4.1.0 -Dclassifier=javadoc
René Link
  • 48,224
  • 13
  • 108
  • 140
  • Today I recognized that someone voted my answer down, but he/she did not leave a comment. Would be nice if a comment could be added, because if there is something wrong I would like to correct it and also learn something for myself too. – René Link Aug 20 '14 at 10:14
  • what is the purpose of groupid and artifactid? – Timeless Jan 15 '15 at 01:57
  • @Timeless the purpose, here https://maven.apache.org/guides/mini/guide-naming-conventions.html is to have a better classification of your project in the repository, among other projects. Check this too. http://stackoverflow.com/questions/3150003/naming-convention-for-maven-artifacts and http://stackoverflow.com/a/12020832/1917237 – n3k0 May 08 '16 at 04:34