1

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.

user2093082
  • 407
  • 8
  • 19

2 Answers2

2

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

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • It is my project, but the goal is to be able to package the jar and give it to third parties to build against. I'm working on the proof of concept to figure out what steps need to be taken, given our jar, to set up a working environment. It would be preferable if we didn't have to package every dependent jar alongside our own. – user2093082 Dec 18 '14 at 21:35
  • I think you misunderstood the purpose of `install`. It will copy the jar to your local repository. Other parties can't reach that, so that's useless in this case. If I read your story correctly, `mvn package` is good enough for you. You might consider `mvn deploy` if there is a server where you can upload your artifacts to. – Robert Scholte Dec 18 '14 at 22:04
  • Updated bug URL is https://issues.apache.org/jira/browse/MINSTALL-110. The fix is to use v3.0.0-M1 or later of install file plugin (eg. org.apache.maven.plugins:maven-install-plugin:3.0.1:install-file) – AlexW Aug 08 '22 at 01:36
-1

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.

Will Iverson
  • 2,009
  • 12
  • 22
  • 1
    I'm testing with my build copy of the jar, but the goal would be that the jar produced can be given to third parties for use with our systems. I'm working on the proof of concept on what steps need to be taken, and I'm hoping that it is not necessary to set up an entire maven repository to download files listed in pom.xml – user2093082 Dec 18 '14 at 21:36
  • Whoever your third party is, if they use Maven a repo will be really nice for them. Check out [this question][1] and this blog for more info. Or [this article][2]. Or [this for private S3 hosting][3]. [1]: http://stackoverflow.com/questions/12525929/maven-repository-hosting-for-non-public-artifacts [2]: http://blog.glassdiary.com/post/65190237091/hosting-your-own-maven-repository-on-github-or [3]: https://github.com/technomancy/s3-wagon-private – Will Iverson Dec 21 '14 at 23:46