user2093082
user2093082

Reputation: 407

Maven install-file isn't resolving dependencies

I am packaging a component into a jar file, and attempting to install it to another system for development. I am installing the file with maven as follows (taken from https://maven.apache.org/plugins/maven-install-plugin/examples/custom-pom-installation.html):

 mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=/home/user/myjar-1.2-SNAPSHOT.jar

Maven reports the jar as being successfully installed:

[INFO] Installing /home/user/myjar-1.2-SNAPSHOT.jar to /home/user/.m2/repository/com/myorg/myjar/1.2-SNAPSHOT/myjar-1.2-SNAPSHOT.jar
[INFO] Installing /tmp/mvninstall1212121212121212121.pom to /home/user/.m2/repository/com/myorg/myjar/1.2-SNAPSHOT/myjar-1.2-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.235s
[INFO] Finished at: Thu Dec 18 14:36:19 EST 2014
[INFO] Final Memory: 9M/93M
[INFO] ------------------------------------------------------------------------

And, I see both the jar and the pom file placed into /home/user/.m2/repository/com/myorg/myjar/1.2-SNAPSHOT/. However, none of the dependencies are being resolved and downloaded by maven. Extracting from myjar and examining META-INF/maven/com.myorg/myjar/pom.xml, I see the dependencies listed as I expect:

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.2.3.RELEASE</version>
  </dependency>
</dependencies>

But the .pom file in my local .m2 repository doesn't list any dependencies or other information about the jar. The only information it contains is:

<?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>com.myorg</groupId>
  <artifactId>myjar</artifactId>
  <version>1.2-SNAPSHOT</version>
  <description>POM was created from install:install-file</description>
</project>

Attempting to code projects which use myjar components leads to exceptions like:

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

Which makes sense, since at no point did maven resolve the dependencies for myjar.

Is there a flag or command I'm missing to have maven resolve these dependencies? If necessary, I can extract the jar to a temporary directory and leverage the pom file directly, but it seems like an unnecessary step when maven is already capable of diving into the jar to find the pom file for the groupId and other fields.

EDIT: To make this clear, while I have access to the source for myjar, the goal is that myjar can be given to third parties without source. I'm trying to identify the steps so that when given myjar, a third party can install it and any related dependencies and develop locally. Preferably with command-line arguments to maven.

Upvotes: 1

Views: 2313

Answers (2)

Will Iverson
Will Iverson

Reputation: 2069

Generally speaking, you should use Maven binary repositories to move files between systems, not install-file. Check out Archiva, Artifactory, and Nexus.

You should treat the mvn local .m2 directory as a cache, not as something to install files into by hand, otherwise you'll find that you are having to spend a lot of time reverse engineering the repository format.

I am packaging a component into a jar file, and attempting to install it to another system for development

From a high level, it looks like you are blurring the line local development builds (snapshots) and release builds (files copied to another server).

I'd say you are going to be happier either just checking out source locally and doing builds there, or else releasing artifacts between systems using a binary repo.

Upvotes: -1

Robert Scholte
Robert Scholte

Reputation: 12335

If this is your project, you should call mvn install. If you are trying to upload a third party jar, which you need and is not available at Maven Central, then you can use install:install-file. However, you're facing a known issue, see https://jira.codehaus.org/browse/MINSTALL-110

Upvotes: 2

Related Questions