Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

java - I want to load all JARs from my libs project folder with Maven

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 <configuration>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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...