프로젝트의 런타임 종속성을 target/lib
폴더에 복사하려면 어떻게합니까?
지금과 mvn clean install
같이 target
폴더에는 내 프로젝트의 jar 만 포함되지만 런타임 종속성은 없습니다.
답변
이것은 나를 위해 작동합니다 :
<project>
...
<profiles>
<profile>
<id>qa</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
답변
가장 좋은 방법은 수행하려는 작업에 따라 다릅니다.
- 종속성을 WAR 또는 EAR 파일로 번들하려면 프로젝트의 패키징 유형을 EAR 또는 WAR로 설정하십시오. Maven은 종속성을 올바른 위치에 묶습니다.
- 모든 종속성과 함께 코드가 포함 된 JAR 파일을 작성 하려면 jar-with-dependencies 설명자 와 함께 어셈블리 플러그인 을 사용하십시오 . Maven은 모든 클래스와 모든 종속성의 클래스로 완전한 JAR 파일을 생성합니다.
- 종속성을 대화식으로 대상 디렉토리로 가져 오려면 종속성 플러그인을 사용 하여 파일을 복사하십시오.
- 다른 유형의 처리에 대한 종속성을 가져 오려면 고유 한 플러그인을 생성해야합니다. 종속성 목록과 디스크에서의 위치를 가져 오는 API가 있습니다. 거기에서 가져 가야합니다 …
답변
mvn install dependency:copy-dependencies
대상 폴더에 작성된 종속성 디렉토리로 나를 위해 작동합니다. 좋아요!
답변
Maven dependency plugin , 특히 dependency : copy-dependencies goal을 살펴보십시오 . The dependency : copy-dependencies mojo 제목 아래 의 예를 살펴보십시오 . 설정 outputDirectory $ {BASEDIR} / 대상 / lib 디렉토리에 구성 속성을 (저는 믿습니다, 당신은 테스트를해야합니다).
도움이 되었기를 바랍니다.
답변
다른 단계의 maven을 사용하지 않고 대상 디렉토리에 종속성을 복사 해야하는 경우 간단하고 우아한 솔루션입니다 (Vaadin으로 작업 할 때 매우 유용합니다).
완벽한 pom 예 :
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${targetdirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
그런 다음 실행 mvn process-sources
jar 파일 종속성은 다음에서 찾을 수 있습니다. /target/dependency
답변
이 작업을 가끔 수행하고 (따라서 POM을 변경하지 않으려면) 다음 명령 줄을 시도하십시오.
mvn 종속성 : 복사 종속성 -DoutputDirectory = $ {project.build.directory} / lib
마지막 인수 를 생략하면 종속성이 배치됩니다 target/dependencies
.
답변
다음과 같이 해보십시오 :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
![](http://daplus.net/wp-content/uploads/2023/04/coupang_part-e1630022808943-2.png)