Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven project defined repository not works

RESOLVED P.S.Because I don't have enough reputation to answer my own question right now so I put the solution in the question.

I just start using Maven with my android project. I use a game engine called libgdx, it's not in the central repo, so I have to install it by myself.

After check the instruction, I use this method.https://stackoverflow.com/q/2230464/531223. I add below defined xml code in root pom.xml

<repositories>
<repository>
  <id>my-local-repo</id>
  <url>file://${basedir}/common/repo</url>
</repository>
</repositories>

And install the jar files I needed successfully with the method in that answer. However, when I execute command mvn install or mvn -o install, it still tell me can't find the jar file. I'm not sure the repository I added in root pom.xml is working.
Can anyone tell me where I made the mistake and how to check whether the project defined repository is working? Thank you.

Thank you Death, I figured it out, it's my silly fault.

In my project, I have 3 module. common android and desktop. I use common/repo dir as my repository. That's why I start use Maven. I did everything is correct except 2 mistake.

1.Put the repository code in root pom.xml not in pom.xml in the android dir which I . I just thought it will works but it isn't.

2.If I put the code in the right dir, I should modify the url, the basedir is changed.

This lesson cost me 3 hours~

like image 454
Matrix Bai Avatar asked Nov 22 '11 08:11

Matrix Bai


2 Answers

I agree with Oleg's answer but if the problem persists after all his steps, check your global settings.xml file for possible usage of the tag.

The mirror settings always point to the same repo and ignore any you might have defined in your project.

e.g. your pom.xml has

<repositories>
    <repository>
        <id>project.local</id>
        <name>project</name>
        <url>file://${project.basedir}/repo</url>
    </repository>
</repositories>

Make sure your <USER_HOME>\.m2\settings.xml ignores it

<mirrors>
    <mirror>
        <id>central</id>
        <name>Central</name>
        <url>http://my.nexus.ip/nexus/content/repositories/central/</url>
        <mirrorOf>!project.local,*</mirrorOf>
    </mirror>
</mirrors>
like image 142
zbubric Avatar answered Oct 14 '22 10:10

zbubric


  1. Run mvn help:effective-pom

  2. Look into the <repositories> section, locate your my-local-repo and look up its real path (excluding file:// prefix)

  3. run this command (from the link you found yourself) mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=/path/to/your.jar -DgroupId=yourGroup -DartifactId=yourArtifactId -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=the_path_you_looked_up_excluding_file://

  4. if (3) produces errors post them here, if not - make sure that folder the_path_you_looked_up_excluding_file:// contains a subfolder structure grp/yourArtifactId/1.0/ with your.jar in there

  5. after all that your project must be able to locate the dependency with this definition

    <dependency>
        <groupId>grp</groupId>
        <artifactId>yourArtifactId</artifactId>
        <version>1.0</version>
    </dependency>
    
like image 23
Oleg Mikheev Avatar answered Oct 14 '22 08:10

Oleg Mikheev