Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven generating pom file

I use maven 3.0.3 and have tried to generate pom for third-party jar like this:

mvn install:install-file -Dfile=cobra.jar -DgroupId=com.cobra -DartifactId=cobra -Dversion=0.98.4 -Dpackaging=jar -DgeneratePom=true

According to link below it should generate proper pom.xml and install artifact in the repo. http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html

Meanwhile, it returns such a error:

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (D:\cobra-0.98.4\lib). Please verify you invoked Maven from the correct directory. -> [Help 1]

Why is it asking for pom.xml while it should generate pom.xml?

like image 493
firen Avatar asked Jul 15 '11 09:07

firen


People also ask

How is POM file generated?

The Install Plugin can create a generic POM in this case which contains the minimal set of POM elements required by Maven, such as groupId, artifactId, version, packaging. You tell Maven to generate a POM by setting the generatePom parameter to true .

What is a POM file in a Maven project?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

Where is the Maven POM file?

It is an XML file that resides in the base directory of the project as pom. xml. The POM contains information about the project and various configuration detail used by Maven to build the project(s).


3 Answers

This is an old question, but was a serious PITA for me for a few minutes, so I thought I'd share:

I just ran into this problem, and I believe that the issue is probably platform-dependent. The real tip-off was that the solution from Cyril's answer wasn't working as expected: despite my specification of -DgroupId=com.xyz and -DartifactId=whatever on the command-line and the corresponding entry in the POM file, the jar was installed in the local repo under com/whatever.

This led me to experiment with quoting command-line arguments, and the eventual correct result from formatting the command-line like this (after deleting the POM file):

mvn install:install-file "-Dfile=cobra.jar" "-DgroupId=com.cobra" "-DartifactId=cobra" "-Dversion=0.98.4" "-Dpackaging=jar" "-DgeneratePom=true"

Some of the quoting is doubtless redundant, but better safe than sorry, right? I happen to be running Vista on this computer, and would not be surprised if this problem were specific to this OS version...by the way, this was with Maven v3.0.4.

like image 194
Keith Layne Avatar answered Oct 19 '22 22:10

Keith Layne


Are you sure that you are executing the install-file goal? I checked your command and it works for me, but when I place a blank install :install-file (maybe you have this typo) the install goal would be used which needs a pom.xml.

Try to use the -X parameter to get more debug information:

 -X,--debug       Produce execution debug output

My system

Maven

c:\>mvn -version

Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\progs\apache-maven-3.0.3
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: c:\Program Files (x86)\Java\jdk1.6.0_21\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

Install Plugin

c:\>mvn -Dplugin=install help:describe

Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install

This plugin has 3 goals:

install:help
  Description: Display help information on maven-install-plugin.
    Call
      mvn install:help -Ddetail=true -Dgoal=<goal-name>
    to display parameter details.

install:install
  Description: Installs the project's main artifact in the local repository.

install:install-file
  Description: Installs a file in the local repository.

For more information, run 'mvn help:describe [...] -Ddetail'
like image 42
FrVaBe Avatar answered Oct 19 '22 23:10

FrVaBe


I found a bypass. You need to create a simple pom.xml like this :

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.cobra</groupId>
    <artifactId>cobra</artifactId>
    <version>0.98.4</version>
</project>

It's not perfect but it's worked for me. If you find a better way to do that, I'm interested.

My config :

$mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/maven
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: /usr/local/jdk1.6.0_20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-25-generic-pae", arch: "i386", family: "unix"

$mvn -Dplugin=install help:describe
...
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
...
like image 43
Cyril Avatar answered Oct 19 '22 23:10

Cyril