I want to load all JARs from my libs project folde

2019-01-29 04:37发布

问题:

I have a Java project using Maven. In my project I have a folder called libs that contains all the JARs that I can't load from internet/external repository.

My issue is how to specify to Maven to include those JARs during packaging, building etc.?

New to Maven, sorry if it is a stupid question.

EDIT : I have an automatic tool that will look up at my pom.xml on my Git to build & deploy my project on different environments. So adding it in local Maven repo, as suggested here will not help since it will work only on my PC. If I add a libs folder with my JARs it will work wherever I am.

Ask me in comments if it's not clear or if I'm mistaken.

回答1:

Contrary to your EDIT adding to the local Maven repo will help and it can be automated as follows:

  • See jtahlborn's answer to Multiple install:install-file in a single pom.xml. (The current version of the maven-install-plugin is 2.5.2. I'd use that rather than the default.)
  • The <configurations>s should look like:

      <configuration>
        <file>${project.basedir}/path/to/your/libs/lib-X.jar</file>
        <repositoryLayout>default</repositoryLayout>
    
        <!-- match the dependency declaration for this artifact -->
        <groupId>logan.wlv</groupId>
        <artifactId>lib-X</artifactId>
        <version>x.y.z</version> 
        <packaging>jar</packaging>
        <!-- -------------------------------------------------- -->
      </configuration>
    
  • Put the install-plugin declaration into a build profile, e.g. lib.

  • Run mvn initialize -P lib once on every new PC (and once after the contents of libs, and hence the install-plugin declaration, changed) before invoking any phase that resolves dependencies first, e.g. compile.

or

  • Automate this even further with:

      <profile>
        <id>lib</id>
        <activation>
          <file>
            <missing>${settings.localRepository}/logan/wlv/lib-X/x.y.z/lib-X-x.y.z.jar</missing>
          </file>
        </activation>
        ...
      <profile>
    

    Such being able to run just mvn initialize without the explicit profile activation the very first time.