tags:

views:

1894

answers:

3

I've installed some third party jars to my repository using the following command:

mvn install:install-file -Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar -DgroupId=nifty-gui -DartifactId=nifty-gui -Dversion=1.0 -Dpackaging=jar

However, once I do mvn compile, maven complains that there is no pom file in the repository and attempts to download it, but can't cause it is not published at any remote repository.

Here is the exact message from maven:

Downloading: http://repo1.maven.org/maven2/nifty-gui/nifty-gui/1.0/nifty-gui-1.0.pom
[INFO] Unable to find resource 'nifty-gui:nifty-gui:pom:1.0' in repository central (http://repo1.maven.org/maven2)

So how do I get maven to generate a pom file for that jar and put it in my local repository?

+2  A: 

The install:install-file goal has an optional parameter generatePom (since version 2.1) that allows to:

Generate a minimal POM for the artifact if none is supplied via the parameter pomFile.
Defaults to true if there is no existing POM in the local repository yet.

This parameter defaults to true since version 2.3 (and false in 2.1, 2.2). So if you're using a version of the install plugin prior to 2.3, you'll have to pass the parameter in the command.

Just in case, the syntax to explicitly use the version 2.3 of the install plugin would be:

mvn org.apache.maven.plugins:maven-install-plugin:2.3:install-file \
    -Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar -DgroupId=nifty-gui \
    -DartifactId=nifty-gui -Dversion=1.0 -Dpackaging=jar
Pascal Thivent
The plug-in documentation says the "generatePom" flag defaults to true, but I have always had to provide it manually. A quick check of the source code for the plug-in looks like it actually defaults to false.
SingleShot
Hmmm. On second glance, I agree the code appears to default to the equivalent of "true". For an explanation of my confusion, see my edit on my answer... Thanks!
SingleShot
+7  A: 

You tell it to! :-)

mvn install:install-file
  -Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar
  -DgroupId=nifty-gui
  -DartifactId=nifty-gui
  -Dversion=1.0
  -Dpackaging=jar
  -DgeneratePom=true

(Command placed on multiple lines so you can easily see the last parameter.)

Nice, huh? In the future you can go to a plug-in's documentation, view its goals, and you can see all the parameters it accepts. For example, the install-file goal.

Edit:

Regarding the question of the default behavior of the generatePom flag, the documentation indicates it defaults to true, and the code appears to support that. However, using Maven 2.0.9 with the maven-install-plugin version 2.2 (both versions are slightly out of date), it does not generate a POM. So, perhaps incrementing the version(s) will allow the default to work.

> touch DeleteMe.jar
> mvn install:install-file -DgroupId=Delete -DartifactId=Me -Dversion=0.0.0 -Dpackaging=jar -Dfile=DeleteMe.jar
...
[INFO] BUILD SUCCESSFUL
...
> ls ~/.m2/repository/Delete/Me/0.0.0/
Me-0.0.0.jar

(No generated POM.)

SingleShot
I wasn't passing the generatePom option because the documentation said it defaults to true. I'll update my software to make sure that everything is in synch. Thanks!
anotherCoder
A: 

Well and in case your third party library really is "nifty gui" all you need to do is to add the nifty maven repository to your pom.xml:

<repositories>
  <repository>
    <id>nifty-maven-repo.sourceforge.net</id>
    <url>http://nifty-gui.sourceforge.net/nifty-maven-repo&lt;/url&gt;
  </repository>
</repositories>

and your maven project will automatically download nifty :D

PS: I know that this was not your actual question but it might help with nifty integration :)

void256