Maven install-file won't generate pom.xml

回眸只為那壹抹淺笑 提交于 2019-12-05 22:59:44

问题


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?


回答1:


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.)




回答2:


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



回答3:


I had the same issue I think as you, I had a shell script using the install:install-file goal like this:

mvn -o install:install-file -e 
  -DgroupId=org.jfree.jcommon 
  -DartifactId=jcommon
  -Dversion=1.0.15
  -Dpackaging=jar
  -Dfile=jcommon-1.0.15.jar 

Couple of things to note:

artifactId cannot contain '.' ... not sure why but the install would fail if this contained '.'

Running the above command only generated a pom with maven 3.x. By adding the following arguments, I was able to get the jar's to be copied:

-DgeneratePom=true -DupdateReleaseInfo=true



回答4:


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</url>
  </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 :)



来源:https://stackoverflow.com/questions/1535729/maven-install-file-wont-generate-pom-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!