1

I have the following child pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
   <parent>
      <groupId>runtime_shared</groupId>
      <artifactId>runtime_shared.master</artifactId>
      <relativePath>../pom.xml</relativePath>
      <version>1.0.0-SNAPSHOT</version>
   </parent>
   <groupId>runtime_shared</groupId>
   <artifactId>javax.vecmath</artifactId>
   <name>javax.vecmath</name>
   <version>1.0.0.qualifier</version>
   <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <id>vecmath</id>
                    <phase>install</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <file>${basedir}/vecmath.jar</file>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                        <packaging>jar</packaging>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

which I want it to install javax.vecmath to my local repository (.m2/repository). Later on I specify this in my parent pom.xml like this:

   <dependency>
         <groupId>runtime_shared</groupId>
         <artifactId>javax.vecmath</artifactId>
         <version>1.0.0.qualifier</version>
   </dependency>

However, when I do mvn install -X I get to see that maven looks for an entirely different path, such as:

[DEBUG]  /home/usr/workspace_runtime/runtime_shared/javax.vecmath/target/javax.vecmath-1.0.0.qualifier.jar

and obviously gives an error. Is it because of some environment variable set wrong, or because of the <file>${basedir}/vecmath.jar</file> tag where ${basedir} refers somewhere else somehow? I also tried using ${project.basedir} but it also did not work.

To give a clearer picture, here is another case:

[DEBUG]  /home/usr/.m2/repository/x/org.apache.felix.main/1.0.0/org.apache.felix.main-1.0.0.jar
[DEBUG]  /home/usr/.m2/repository/x/org.apache.felix.gogo/0.10.0/org.apache.felix.gogo-0.10.0.jar
[DEBUG]  /home/usr/workspace_runtime/x/com.google.protobuf/target/com.google.protobuf-2.5.0.jar

If you notice, with the first two projects the directory is correct. However, the last one, somehow is looked under the wrong directory. And as a result:

package com.google.protobuf does not exist

Any suggestions?

Schütze
  • 1,044
  • 5
  • 28
  • 48
  • Remove this configuration of the `maven-install-plugin`, You don't need it, just invoke `mvn clean install`. – Tunaki Jul 05 '16 at 10:28
  • Then how is it going to add the jar file to the local repository? I refer to the jar in that configuration section, if you notice. – Schütze Jul 05 '16 at 10:30
  • `install` will install the jar to your local repo automatically. – Tunaki Jul 05 '16 at 10:30
  • And how is it going to know the path of the jar? My jar is in the same folder of my project, and it needs to be installed into the local repository (`.m2/repository`). This `plugin` does this task. It installs whatever you give as a jar (with its path) to the `.m2/repository`. Without giving any path, it cannot find the jar to install it. – Schütze Jul 05 '16 at 10:33
  • The Maven project has a packaging of type `jar`, which is the default. This project generates an artifact, which is a JAR file and it attaches it to the build. When the Install plugin kicks in in the `install` phase, it finds it automatically as the artifact is attached to the build. This is the standard set-up of a Maven build, no need to specify any path or anything. – Tunaki Jul 05 '16 at 11:10
  • I have a local third party in my project, and this is the way I add it to my local repository. Now, if you say maven can find my third party local jar without any path; this is news to me. In that case, thank you for letting me know. – Schütze Jul 05 '16 at 11:13
  • This is a 3rd party library? But you are working on a `javax.vecmath` project and installing `vecmath.jar`, is this not your code? – Tunaki Jul 05 '16 at 11:20
  • `javax.vecmath` is a project that only contains a jar called `vecmath`, apart from this, there is no purpose of this project. I want to use this as a dependency in another project, so I install its jar by using the plugin, and then use it as a dependency. – Schütze Jul 05 '16 at 11:28

1 Answers1

0

If you declare a Maven project with:

<groupId>runtime_shared</groupId>
<artifactId>javax.vecmath</artifactId>
<version>1.0.0.qualifier</version>

it means that this is YOUR project in which Maven:

It's not meant to add 3rd-party artifacts (like javax.vecmath:vecmath) to any of your repositories.

See, once again, points 1. and 2. of the answer to your question a few days ago for how to put 3rd-party artifacts into your repositories, be it local or remote.

Community
  • 1
  • 1
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • But I can add jars to my local repository through `maven-install-plugin`. It does add the jar, I browsed the folder and it's there. Is it a wrong usage of it? – Schütze Jul 05 '16 at 12:34
  • And I've said this thousands of times, that I cannot use terminal commands to add the third party artifacts. This is the reason why I am looking for a plugin which does this magic. – Schütze Jul 05 '16 at 12:35
  • If you cannot use terminal commands, how can you use Maven at all? – J Fabian Meier Jul 05 '16 at 12:42
  • Let's put it this way: `mvn install` is okay, however the rest is not. So I am looking for a way to make [this](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html) work with only `mvn install`. – Schütze Jul 05 '16 at 12:43
  • Just for curiousity: What is the rationale behind this restriction? – J Fabian Meier Jul 05 '16 at 12:44
  • @Schütze "_A thousand of times_"? I read it [just once](http://stackoverflow.com/q/38123749/1744774): "_Any command line argument is not acceptable, since this will run on jenkins and there are other complications_". What has Jenkins to do with your command line and what are the complications with Jenkins running command line tasks? If you keep insisting to work more against Maven rather than with it, it's up to you, of course. Good luck then! – Gerold Broser Jul 05 '16 at 12:56