How to simply download a JAR using Maven?

后端 未结 12 552
轮回少年
轮回少年 2020-12-04 10:14

How do I download JAR during a build in Maven script?

相关标签:
12条回答
  • 2020-12-04 10:45

    Maven does not work like that. Here's the closest you'll get to my knowledge:

    mvn dependency:get -DremoteRepositories=http://repo1.maven.org/maven2/ \
                       -DgroupId=junit -DartifactId=junit -Dversion=4.8.2 \
                       -Dtransitive=false
    

    Note that all parameters except transitive are required.
    Also note that Maven will download the jar to your local repository, and there's no sensible way (that I know of) to copy it to a local directory.

    Reference:

    • dependency:get
    0 讨论(0)
  • 2020-12-04 10:45

    Note: This answer is for downloading the jars directly from maven without any scripts [That is how Google directed me here]

    Assuming mvn dependency is like this:

    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>2.4.7</version>
    </dependency>
    

    Goto http://search.maven.org and search for g:"com.zaxxer" AND a:"HikariCP" AND v:"2.4.7" (simply searching for HikariCP also works. You may need to select the appropriate GroupId and Version from the results)

    In the Search Results -> Download column, you should see jar javadoc.jar sources.jar available for direct download

    0 讨论(0)
  • 2020-12-04 10:45

    You can setup a pom.xml to define your dependencies (the jars you want to copy). Then use the dependency:copy-dependencies goal to copy the jars to the desired location.

    0 讨论(0)
  • 2020-12-04 10:46

    Normally you don't use Maven for "just downloading", but for your build process. So normally, you do the following steps:

    1. Define a new project by defining the archetype of your project and some needed properties.
    2. Define as a dependency the library you want to use.
    3. Run Maven with mvn compile

    As a side effect, you will have downloaded the library to your local Maven repository. There are a lot of plugins to do something with dependencies, so have e.g. a look at the Maven Dependency plugin.

    0 讨论(0)
  • 2020-12-04 10:46

    Use the below code snip

    result = subprocess.check_output('mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
                                         -DgroupId=%s \
                                         -DartifactId=%s \
                                         -Dversion=%s \
                                         -Dtransitive=false \
                                         -DremoteRepositories={repos_string} \
                                         -Dpackaging=jar \
                                         -DoutputDirectory=%s' % (group_id,
                                                                  artifact_id,
                                                                  version_name,
                                                                  des_path), shell=True)
        logger.info("success download jar: %s" % each_version)
    except Exception as e:
        logger.error("Error in download jar : %s" % str(e))
    
    0 讨论(0)
  • 2020-12-04 10:50

    If you just want to download a JAR once from a maven mirror I suggest you could just do this manually:

    For Maven 1:
    http://mirrors.ibiblio.org/pub/mirrors/maven/

    For Maven 2:
    http://mirrors.ibiblio.org/pub/mirrors/maven2/

    These are the repositories (a mirror anyway) that maven will get its JARs from - you can easily access them in the webbrowser of your choice and download the JARs etc. Just browse through the hierarchy (it looks like any Java packag hierarchy) until you find the artefact, then pick the right version and you're good.

    For example version 3.6.6.Final of hibernate-core from group org.hibernate you'd find here:

    http://mirrors.ibiblio.org/pub/mirrors/maven2/org/hibernate/hibernate-core/3.6.6.Final/

    0 讨论(0)
提交回复
热议问题