github email
快速下载所需的Jar
Nov 6, 2018
One minute read

使用maven下载jar到本地

原来使用Java进行项目开发的时候,都是使用浏览器一个一个jar进行下载,放到lib目录中使用。 最近,发现使用maven的效率更高,所以,使用该方法。

1.创建一个pom.xml文件。

<?xml version="1.0"?>
<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>
    <groupId>com.bingyi</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <repositories>
        <!-- <repository><id>central-repos2</id><name>Central Repository 2</name><url>http://repo.spring.io/plugins-release</url></repository> -->
        <!-- <repository><id>maven.net.cn</id><name>oneof the central mirrors in china</name><url>http://maven.net.cn/content/groups/public/</url></repository> -->
       
        <repository>
            <id>oschina-repos</id>
            <name>Oschina Releases</name>
            <url>http://maven.oschina.net/content/groups/public</url>
        </repository>
        <!-- <repository><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url></repository> -->
        <!-- <repository><id>central</id><name>Maven Repository Switchboard</name><url>http://repo1.maven.org/maven2/</url></repository> -->
    </repositories>
    <dependencies>
        <!-- TODO: add you need jar -->
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.8</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

2.创建执行脚本 downloadjar.bat

call mvn -f pom.xml dependency:copy-dependencies
@pause

3.mac下创建shell脚本 downloadjar.sh

mvn -f pom.xml dependency:copy-dependencies
echo 'done!'

Back to posts