Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven does not read POM when installing JAR to repository

I've followed the guide here to install a JAR file into my local repository.

I run following command:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar

The JAR file is built using Maven and contains a POM file inside it listing its dependencies. The file inside JAR has the path:

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml

Maven installs the artifact but does not read its POM. It creates an empty POM file which is void of any dependency info:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>in.ksharma</groupId>
  <artifactId>log4j-weblayout</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>POM was created from install:install-file</description>
</project>

How can I ensure that the POM inside the JAR is the one that is installed?

Edit:

Contents of various files inside the JAR are as follows.

/META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: kshitiz
Created-By: Apache Maven 3.1.0
Build-Jdk: 1.8.0

/META-INF/maven/in.ksharma/log4j-weblayout/pom.properties:

#Generated by Maven
#Wed Oct 08 19:48:28 IST 2014
version=0.0.1-SNAPSHOT
groupId=in.ksharma
artifactId=log4j-weblayout

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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>in.ksharma</groupId>
    <artifactId>log4j-weblayout</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <url>https://github.com/Kshitiz-Sharma/log4j-weblayout</url>
    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <!-- Compile dependencies -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>joor</artifactId>
            <version>0.9.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
            <scope>compile</scope>
        </dependency>

        <!-- Provided dependencies -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.1.8</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</project>
like image 639
Kshitiz Sharma Avatar asked Oct 08 '14 14:10

Kshitiz Sharma


People also ask

What is the command to install jar in Maven local repository?

In this case you can perform mvn initialize and jar will be installed in local maven repo. Now this jar is available during any maven step on this machine (do not forget to include this dependency as any other maven dependency in pom with <dependency></dependency> tag).

Why are Maven dependencies not being downloaded?

Maven uses HTTP to download its dependencies along with the dependencies of the Maven project (such as Camel). If you run Maven and it fails to download your required dependencies it's likely to be caused by your local firewall & HTTP proxy configurations.

Does JAR file contains POM XML?

When Maven builds a JAR file, it places the module's POM file inside (seemingly in the directory <groupid>/<artifactid>).


2 Answers

I think you'll need to extract the pom.xml from the jar and specify it using the pomFile property as follows:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar -DpomFile=pom.xml
like image 100
Ryan Hoegg Avatar answered Oct 14 '22 20:10

Ryan Hoegg


Seems to be fixed in 3.0.0-M1 version of install plugin, but maven might still use 2.5.2 as a default. You can set the version of the install plugin in your pluginManagement section:

  <pluginManagement>
      <plugins>
      ...
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>3.0.0-M1</version>
        </plugin>
      ...
      </plugins>
  </pluginManagement>

or call the right version of the plugin on the command line:

mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar
like image 21
Jens Viebig Avatar answered Oct 14 '22 20:10

Jens Viebig