maven构建项目时,下载的jar放在项目的lib目录中

来源:互联网 发布:玄铁重剑淘宝 编辑:程序博客网 时间:2024/06/09 17:17

    我们在使用Maven构建项目的时候,pom.xml下载下来的jar包是在本地仓库中,往往有些同学是需要或者习惯于在项目的lib目录下找jar包,那么我们只需要在pom.xml中最后加上以下代码:

<build> 
        <plugins> 
          

<plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-dependency-plugin</artifactId>            <executions>                <execution>                    <id>copy-dependencies</id>                    <phase>prepare-package</phase>                    <goals>                        <goal>copy-dependencies</goal>                    </goals>                    <configuration>                        <outputDirectory>${project.build.directory}/lib</outputDirectory>                        <overWriteReleases>false</overWriteReleases>                        <overWriteSnapshots>false</overWriteSnapshots>                        <overWriteIfNewer>true</overWriteIfNewer>                    </configuration>                </execution>            </executions>        </plugin>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-jar-plugin</artifactId>            <configuration>                <archive>                    <manifest>                        <addClasspath>true</addClasspath>                        <classpathPrefix>lib/</classpathPrefix>                        <mainClass>theMainClass</mainClass>                    </manifest>                </archive>            </configuration>        </plugin>    </plugins> 
    </build>



注明:会在target生成lib目录以及相应的JAR

2 0
原创粉丝点击