How to manually install an artifact in Maven 2?
Asked Answered
S

6

100

I've encountered some errors when I tried to install an artifact manually with Maven 2. I wanted to install a jar from a local directory with the command

mvn install:install-file -Dfile=jta-1.0.1B.jar

But Maven gave a build error which reads like:

Invalid task '.01B.jar': you must
specify a valid lifecycle phase, or a
goal in the format plugin:goal or
pluginGroupId:pluginArtifactId:pluginVersion:goal

Is there a mistake with my command?

Sealey answered 14/1, 2009 at 7:54 Comment(1)
What is the status of this? Is you question resolved?Reduplicate
P
156

You need to indicate the groupId, the artifactId and the version for your artifact:

mvn install:install-file \
  -DgroupId=javax.transaction \
  -DartifactId=jta \
  -Dpackaging=jar \
  -Dversion=1.0.1B \
  -Dfile=jta-1.0.1B.jar \
  -DgeneratePom=true
Penurious answered 14/1, 2009 at 8:6 Comment(7)
-Dpackaging=jar or similar is missingJahdiel
@Jahdiel No! By default, the packaging is jar, so you don't need to specify this in thé command...Penurious
does not work for me too: Missing group, artifact, version, or packaging informationBullbat
@romaintaz kaboom is correct; you need -Dpackaging=jar (or whatever the type is) otherwise you will get an error about "'packaging' is missing."Medea
It seems that the packaging parameter is needed except if you provide a pom file. In the latter case, the type of package is taken from the pom.Penurious
+1 for -DgeneratePom=true. Otherwise you get warnings when using the artifact that the pom is missing.Hakon
If using PowerShell, make sure you use quote likewise "-DgroupId=javax.transaction"Deformity
B
39

According to maven's Guide to installing 3rd party JARs, the command is:

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

You need indeed the packaging option. This answers the original question.

Now, in your context, you are fighting with a jar provided by Sun. You should read the Coping with Sun JARs page too. There, you'll learn how to help maven to provide you better information about Sun jars location and how to add Java.net Maven 2 repository which contains jta-1.0.1B.jar. Add this in your settings.xml (not portable) or pom.xml (portable):

  <repositories>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven</name>
      <url>http://download.java.net/maven/2/</url>
      <layout>default</layout>
    </repository>
  </repositories>
Burkitt answered 13/3, 2009 at 23:4 Comment(0)
V
16

I had to add packaging, so:

mvn install:install-file \
  -DgroupId=javax.transaction \
  -DartifactId=jta \
  -Dversion=1.0.1B \
  -Dfile=jta-1.0.1B.jar \
  -DgeneratePom=true \
  -Dpackaging=jar
Volkman answered 3/3, 2009 at 16:45 Comment(1)
I had lots of issues installing a jar file manually, and it kept failing until I typed it this way exactly. Now it works!Amply
Z
8

Answer is to escape the dash!

http://www.mail-archive.com/[email protected]/msg83991.html

Zamir answered 27/9, 2010 at 11:47 Comment(1)
Damm me. that was it. all the -D parameters must be enclosed in `.Adminicle
H
4

If you ever get similar errors when using Windows PowerShell, you should try Windows' simple command-line. I didn't find out what caused this, but PowerShell seems to interpret some of Maven's parameters.

Hawkbill answered 14/5, 2010 at 10:0 Comment(2)
Look at S. Bollweber answer above. And at least TakeCommand expresses the same bahaviour.Adminicle
No reason to downvote my answer – S. Bollweber answered a few months after myself.Hawkbill
A
2

All the posted answers rightfully discuss this from a strictly maven perspective. My issues was in doing this install for maven using Netbeans as my primary IDE. I found the below article helpful.

Credit to the following netbeans forum article: http://forums.netbeans.org/topic22907.html

  1. In Maven project open "Add dependency" dialog
  2. Make up some groupId, artifactId and version and fill them, OK.
  3. Dependency will be added to the pom.xml and will appear under "Libraries" node of maven project
  4. Right-click Lib node and "manually install artifact", fill the path to the jar. Jar should be installed to local Maven repo with coordinates entered in step 2)
Anile answered 24/1, 2014 at 19:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.