Mic*_*ael 241 java dependencies maven-2 maven-3 maven
如何将项目的运行时依赖项复制到target/lib
文件夹中?
因为它是现在,后mvn clean install
的target
文件夹仅包含我的项目的罐子,但没有运行时依赖的.
Geo*_*uba 254
这对我有用:
<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>
Run Code Online (Sandbox Code Playgroud)
Joh*_*fer 83
最好的方法取决于你想做什么:
小智 72
mvn install dependency:copy-dependencies
Run Code Online (Sandbox Code Playgroud)
适用于我在目标文件夹中创建的依赖项目录.喜欢它!
Tra*_*ell 34
看一下Maven依赖插件,特别是依赖:copy-dependencies目标.看一下标题The dependency:copy-dependencies mojo下的示例.将outputDirectory配置属性设置为$ {basedir}/target/lib(我相信,你必须测试).
希望这可以帮助.
ruh*_*kus 30
一个简单而优雅的解决方案,用于需要将依赖项复制到目标目录而不使用任何其他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>
Run Code Online (Sandbox Code Playgroud)
然后跑 mvn process-sources
可以在中找到jar文件依赖项 /target/dependency
小智 24
尝试这样的事情:
<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>
Run Code Online (Sandbox Code Playgroud)
Dun*_*nes 23
如果您想偶尔执行此操作(因此不想更改POM),请尝试以下命令行:
mvn dependency:copy-dependencies -DoutputDirectory=${project.build.directory}/lib
如果省略最后一个参数,则放置依赖关系target/dependencies
.
isa*_*pir 14
您所需要的只是pom.xml中的以下代码段build/plugins
:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
package
当你跑步时,上面将运行
mvn clean package
Run Code Online (Sandbox Code Playgroud)
并且依赖项将被复制到代码段中指定的outputDirectory,即lib
在这种情况下.
如果您只想偶尔这样做,那么不需要更改pom.xml.只需运行以下命令:
mvn clean package dependency:copy-dependencies
Run Code Online (Sandbox Code Playgroud)
要覆盖默认位置,即${project.build.directory}/dependencies
添加一个名为的System属性outputDirectory
,即
-DoutputDirectory=${project.build.directory}/lib
Run Code Online (Sandbox Code Playgroud)
小智 7
假如
这对我有用:
mvn install dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib
如果您想提供应用程序jar包及其所有依赖项和一些脚本来调用MainClass,请查看appassembler-maven-plugin.
以下配置将为Window和Linux生成脚本以启动应用程序(使用生成的路径引用所有依赖项jar,下载所有依赖项(到target/appassembler下面的lib文件夹中).然后可以使用程序集插件来打包整个appassembler目录到一个zip,它与jar一起安装/部署到存储库.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
<configuration>
<!--declare the JSW config -->
<daemons>
<daemon>
<id>myApp</id>
<mainClass>name.seller.rich.MyMainClass</mainClass>
<commandLineArguments>
<commandLineArgument>start</commandLineArgument>
</commandLineArguments>
<platforms>
<platform>jsw</platform>
</platforms>
</daemon>
</daemons>
<target>${project.build.directory}/appassembler</target>
</configuration>
</execution>
<execution>
<id>assemble-standalone</id>
<phase>integration-test</phase>
<goals>
<goal>assemble</goal>
</goals>
<configuration>
<programs>
<program>
<mainClass>name.seller.rich.MyMainClass</mainClass>
<!-- the name of the bat/sh files to be generated -->
<name>mymain</name>
</program>
</programs>
<platforms>
<platform>windows</platform>
<platform>unix</platform>
</platforms>
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/archive.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
用于将direcotry打包为zip的汇编描述符(在src/main/assembly中)将是:
<assembly>
<id>archive</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/appassembler</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
243877 次 |
最近记录: |