How do I get my project's runtime dependencies copied into the target/lib
folder?
如何将项目的运行时依赖项复制到目标/lib文件夹中?
As it is right now, after mvn clean install
the target
folder contains only my project's jar, but none of the runtime dependencies.
现在,在mvn clean安装之后,目标文件夹只包含项目的jar,没有运行时依赖项。
16 个解决方案
#1
227
This works for me:
这工作对我来说:
<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>
#2
74
The best approach depends on what you want to do:
最好的方法取决于你想做什么:
- If you want to bundle your dependencies into a WAR or EAR file, then simply set the packaging type of your project to EAR or WAR. Maven will bundle the dependencies into the right location.
- 如果您想将依赖项捆绑到WAR或EAR文件中,那么只需将项目的打包类型设置为EAR或WAR。Maven将把依赖项绑定到正确的位置。
- If you want to create a JAR file that includes your code along with all your dependencies, then use the assembly plugin with the jar-with-dependencies descriptor. Maven will generate a complete JAR file with all your classes plus the classes from any dependencies.
- 如果您想要创建一个JAR文件,其中包含您的代码和所有依赖项,那么请使用带有JAR -with-dependencies描述符的程序集插件。Maven将生成一个完整的JAR文件,其中包含所有的类以及来自任何依赖项的类。
- If you want to simply pull your dependencies into the target directory interactively, then use the dependency plugin to copy your files in.
- 如果您想简单地将您的依赖项插入到目标目录中,那么使用依赖插件来复制您的文件。
- If you want to pull in the dependencies for some other type of processing, then you will probably need to generate your own plugin. There are APIs to get the list of dependencies, and their location on disk. You will have to take it from there...
- 如果您想为其他类型的处理引入依赖项,那么您可能需要生成自己的插件。有一些api可以获取依赖项列表,以及它们在磁盘上的位置。你必须从那里得到它……
#3
58
mvn install dependency:copy-dependencies
Works for me with dependencies directory created in target folder. Like it!
在目标文件夹中创建依赖项目录的工作。喜欢它!
#4
32
Take a look at the Maven dependency plugin, specifically, the dependency:copy-dependencies goal. Take a look at the example under the heading The dependency:copy-dependencies mojo. Set the outputDirectory configuration property to ${basedir}/target/lib (I believe, you'll have to test).
看看Maven依赖插件,特别是依赖项:复制依赖目标。请查看标题“依赖项:复制依赖项mojo”下的示例。将outputDirectory配置属性设置为${basedir}/target/lib(我相信,您必须进行测试)。
Hope this helps.
希望这个有帮助。
#5
29
A simple and elegant solution for the case where one needs to copy the dependencies to a target directory without using any other phases of maven (I found this very useful when working with Vaadin).
对于需要将依赖项复制到目标目录而不使用maven的其他阶段的情况,一个简单而优雅的解决方案(我在与Vaadin合作时发现这非常有用)。
Complete pom example:
完整的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>
Then run mvn process-sources
然后运行mvn process-sources
The jar file dependencies can be found in /target/dependency
jar文件依赖项可以在/target/依赖项中找到
#6
20
If you want to do this on an occasional basis (and thus don't want to change your POM), try this command-line:
如果您希望偶尔这样做(因此不希望更改POM),请尝试以下命令行:
mvn dependency:copy-dependencies -DoutputDirectory=${project.build.directory}/lib
If you omit the last argument, the dependences are placed in target/dependencies
.
如果忽略最后一个参数,则依赖项被放在目标/依赖项中。
#7
20
Try something like this:
试试这样:
<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>
#8
5
supposing
假设
- you don't want to alter the pom.xml
- 您不希望修改这个poml .xml
- you don't want test scoped (e.g. junit.jar) or provided dependencies (e.g. wlfullclient.jar)
- 您不希望测试作用域(例如junit.jar)或提供依赖项(例如wlfullclient.jar)
here ist what worked for me:
以下是对我有用的东西:
mvn install dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib
#9
5
All you need is the following snippet inside pom.xml's build/plugins
:
您所需要的只是pom中的以下代码片段。xml的构建/插件:
<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>
The above will run in the package
phase when you run
当您运行时,上面的操作将在包阶段运行
mvn clean package
And the dependencies will be copied to the outputDirectory specified in the snippet, i.e. lib
in this case.
依赖项将被复制到代码片段中指定的outputDirectory,即本例中的lib。
If you only want to do that occasionally, then no changes to pom.xml are required. Simply run the following:
如果您只是偶尔想要这样做,那么pom就没有变化。xml是必需的。简单地运行以下:
mvn clean package dependency:copy-dependencies
To override the default location, which is ${project.build.directory}/dependencies
, add a System property named outputDirectory
, i.e.
要覆盖默认位置,即${project.build。目录}/依赖项,添加一个名为outputDirectory的系统属性,即。
-DoutputDirectory=${project.build.directory}/lib
#10
4
If you want to deliver a bundle of your application jar, together with all it's dependencies and some scripts to invoke the MainClass, look at the appassembler-maven-plugin.
如果您想交付一束应用程序jar,以及它所有的依赖项和一些调用主类的脚本,请查看appassembly -maven-plugin。
The following configuration will generate scripts for Window and Linux to launch the application (with a generated path referencing all the dependency jars, download all dependencies (into a lib folder below target/appassembler). The assembly plugin can then be used to package the whole appassembler directory to a zip which is installed/deployed along with the jar to the repository.
以下配置将为windows和Linux生成启动应用程序的脚本(生成的路径引用所有依赖项jar,下载所有依赖项(到target/appassembler下方的lib文件夹中)。然后可以使用这个插件程序集将整个appassembler目录打包为一个zip,该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>
The assembly descriptor (in src/main/assembly) to package the direcotry as a zip would be:
将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>
#11
2
If you make your project a war or ear type maven will copy the dependencies.
如果您使您的项目成为战争或ear类型的maven,将复制依赖项。
#12
2
You can use the the Shade Plugin to create an uber jar in which you can bundle all your 3rd party dependencies.
您可以使用Shade插件创建一个uber jar,在其中绑定所有第三方依赖项。
#13
1
Just to spell out what has already been said in brief. I wanted to create an executable JAR file that included my dependencies along with my code. This worked for me:
只是简单地说明一下已经说过的内容。我想创建一个可执行的JAR文件,其中包括我的依赖项和代码。这工作对我来说:
(1) In the pom, under <build><plugins>, I included:
(1)在pom中,在
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>dk.certifikat.oces2.some.package.MyMainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
(2) Running mvn compile assembly:assembly produced the desired my-project-0.1-SNAPSHOT-jar-with-dependencies.jar in the project's target directory.
(2)运行mvn编译程序集:程序集生成所需的my-project-0.1-SNAPSHOT-jar-with-dependencies。jar在项目的目标目录中。
(3) I ran the JAR with java -jar my-project-0.1-SNAPSHOT-jar-with-dependencies.jar
(3)我使用java -jar my-project-0.1- snapshote -jar with- dependent . JAR来运行JAR
#14
1
It's a heavy solution for embedding heavy dependencies, but Maven's Assembly Plugin does the trick for me.
对于嵌入大量依赖项来说,这是一个繁重的解决方案,但是Maven的汇编插件为我提供了解决方案。
@Rich Seller's answer should work, although for simpler cases you should only need this excerpt from the usage guide:
@Rich Seller的回答应该是有效的,尽管对于更简单的情况,你只需要从使用指南中摘录以下内容:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
#15
0
If you're having problems related to dependencies not appearing in the WEB-INF/lib file when running on a Tomcat server in Eclipse, take a look at this:
如果您在Eclipse的Tomcat服务器上运行时遇到依赖项没有出现在WEB-INF/lib文件中的问题,请查看以下内容:
在启动Tomcat时,ClassNotFoundException (Maven依赖项没有复制到wtpwebapps)
You simply had to add the Maven Dependencies in Project Properties > Deployment Assembly.
您只需在项目属性>部署程序集中添加Maven依赖项。
#16
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.edge</groupId>
<artifactId>STORM2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>STORM2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.edge.STORM2.LogAnalyserStorm</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@john This is my pom, am I missing something? the created jar-with dependencies, doesnt contain any lib class or jar
这是我的pom,我漏掉了什么吗?创建的jar-with依赖项,不包含任何lib类或jar
#1
227
This works for me:
这工作对我来说:
<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>
#2
74
The best approach depends on what you want to do:
最好的方法取决于你想做什么:
- If you want to bundle your dependencies into a WAR or EAR file, then simply set the packaging type of your project to EAR or WAR. Maven will bundle the dependencies into the right location.
- 如果您想将依赖项捆绑到WAR或EAR文件中,那么只需将项目的打包类型设置为EAR或WAR。Maven将把依赖项绑定到正确的位置。
- If you want to create a JAR file that includes your code along with all your dependencies, then use the assembly plugin with the jar-with-dependencies descriptor. Maven will generate a complete JAR file with all your classes plus the classes from any dependencies.
- 如果您想要创建一个JAR文件,其中包含您的代码和所有依赖项,那么请使用带有JAR -with-dependencies描述符的程序集插件。Maven将生成一个完整的JAR文件,其中包含所有的类以及来自任何依赖项的类。
- If you want to simply pull your dependencies into the target directory interactively, then use the dependency plugin to copy your files in.
- 如果您想简单地将您的依赖项插入到目标目录中,那么使用依赖插件来复制您的文件。
- If you want to pull in the dependencies for some other type of processing, then you will probably need to generate your own plugin. There are APIs to get the list of dependencies, and their location on disk. You will have to take it from there...
- 如果您想为其他类型的处理引入依赖项,那么您可能需要生成自己的插件。有一些api可以获取依赖项列表,以及它们在磁盘上的位置。你必须从那里得到它……
#3
58
mvn install dependency:copy-dependencies
Works for me with dependencies directory created in target folder. Like it!
在目标文件夹中创建依赖项目录的工作。喜欢它!
#4
32
Take a look at the Maven dependency plugin, specifically, the dependency:copy-dependencies goal. Take a look at the example under the heading The dependency:copy-dependencies mojo. Set the outputDirectory configuration property to ${basedir}/target/lib (I believe, you'll have to test).
看看Maven依赖插件,特别是依赖项:复制依赖目标。请查看标题“依赖项:复制依赖项mojo”下的示例。将outputDirectory配置属性设置为${basedir}/target/lib(我相信,您必须进行测试)。
Hope this helps.
希望这个有帮助。
#5
29
A simple and elegant solution for the case where one needs to copy the dependencies to a target directory without using any other phases of maven (I found this very useful when working with Vaadin).
对于需要将依赖项复制到目标目录而不使用maven的其他阶段的情况,一个简单而优雅的解决方案(我在与Vaadin合作时发现这非常有用)。
Complete pom example:
完整的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>
Then run mvn process-sources
然后运行mvn process-sources
The jar file dependencies can be found in /target/dependency
jar文件依赖项可以在/target/依赖项中找到
#6
20
If you want to do this on an occasional basis (and thus don't want to change your POM), try this command-line:
如果您希望偶尔这样做(因此不希望更改POM),请尝试以下命令行:
mvn dependency:copy-dependencies -DoutputDirectory=${project.build.directory}/lib
If you omit the last argument, the dependences are placed in target/dependencies
.
如果忽略最后一个参数,则依赖项被放在目标/依赖项中。
#7
20
Try something like this:
试试这样:
<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>
#8
5
supposing
假设
- you don't want to alter the pom.xml
- 您不希望修改这个poml .xml
- you don't want test scoped (e.g. junit.jar) or provided dependencies (e.g. wlfullclient.jar)
- 您不希望测试作用域(例如junit.jar)或提供依赖项(例如wlfullclient.jar)
here ist what worked for me:
以下是对我有用的东西:
mvn install dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib
#9
5
All you need is the following snippet inside pom.xml's build/plugins
:
您所需要的只是pom中的以下代码片段。xml的构建/插件:
<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>
The above will run in the package
phase when you run
当您运行时,上面的操作将在包阶段运行
mvn clean package
And the dependencies will be copied to the outputDirectory specified in the snippet, i.e. lib
in this case.
依赖项将被复制到代码片段中指定的outputDirectory,即本例中的lib。
If you only want to do that occasionally, then no changes to pom.xml are required. Simply run the following:
如果您只是偶尔想要这样做,那么pom就没有变化。xml是必需的。简单地运行以下:
mvn clean package dependency:copy-dependencies
To override the default location, which is ${project.build.directory}/dependencies
, add a System property named outputDirectory
, i.e.
要覆盖默认位置,即${project.build。目录}/依赖项,添加一个名为outputDirectory的系统属性,即。
-DoutputDirectory=${project.build.directory}/lib
#10
4
If you want to deliver a bundle of your application jar, together with all it's dependencies and some scripts to invoke the MainClass, look at the appassembler-maven-plugin.
如果您想交付一束应用程序jar,以及它所有的依赖项和一些调用主类的脚本,请查看appassembly -maven-plugin。
The following configuration will generate scripts for Window and Linux to launch the application (with a generated path referencing all the dependency jars, download all dependencies (into a lib folder below target/appassembler). The assembly plugin can then be used to package the whole appassembler directory to a zip which is installed/deployed along with the jar to the repository.
以下配置将为windows和Linux生成启动应用程序的脚本(生成的路径引用所有依赖项jar,下载所有依赖项(到target/appassembler下方的lib文件夹中)。然后可以使用这个插件程序集将整个appassembler目录打包为一个zip,该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>
The assembly descriptor (in src/main/assembly) to package the direcotry as a zip would be:
将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>
#11
2
If you make your project a war or ear type maven will copy the dependencies.
如果您使您的项目成为战争或ear类型的maven,将复制依赖项。
#12
2
You can use the the Shade Plugin to create an uber jar in which you can bundle all your 3rd party dependencies.
您可以使用Shade插件创建一个uber jar,在其中绑定所有第三方依赖项。
#13
1
Just to spell out what has already been said in brief. I wanted to create an executable JAR file that included my dependencies along with my code. This worked for me:
只是简单地说明一下已经说过的内容。我想创建一个可执行的JAR文件,其中包括我的依赖项和代码。这工作对我来说:
(1) In the pom, under <build><plugins>, I included:
(1)在pom中,在
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>dk.certifikat.oces2.some.package.MyMainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
(2) Running mvn compile assembly:assembly produced the desired my-project-0.1-SNAPSHOT-jar-with-dependencies.jar in the project's target directory.
(2)运行mvn编译程序集:程序集生成所需的my-project-0.1-SNAPSHOT-jar-with-dependencies。jar在项目的目标目录中。
(3) I ran the JAR with java -jar my-project-0.1-SNAPSHOT-jar-with-dependencies.jar
(3)我使用java -jar my-project-0.1- snapshote -jar with- dependent . JAR来运行JAR
#14
1
It's a heavy solution for embedding heavy dependencies, but Maven's Assembly Plugin does the trick for me.
对于嵌入大量依赖项来说,这是一个繁重的解决方案,但是Maven的汇编插件为我提供了解决方案。
@Rich Seller's answer should work, although for simpler cases you should only need this excerpt from the usage guide:
@Rich Seller的回答应该是有效的,尽管对于更简单的情况,你只需要从使用指南中摘录以下内容:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
#15
0
If you're having problems related to dependencies not appearing in the WEB-INF/lib file when running on a Tomcat server in Eclipse, take a look at this:
如果您在Eclipse的Tomcat服务器上运行时遇到依赖项没有出现在WEB-INF/lib文件中的问题,请查看以下内容:
在启动Tomcat时,ClassNotFoundException (Maven依赖项没有复制到wtpwebapps)
You simply had to add the Maven Dependencies in Project Properties > Deployment Assembly.
您只需在项目属性>部署程序集中添加Maven依赖项。
#16
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.edge</groupId>
<artifactId>STORM2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>STORM2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.edge.STORM2.LogAnalyserStorm</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@john This is my pom, am I missing something? the created jar-with dependencies, doesnt contain any lib class or jar
这是我的pom,我漏掉了什么吗?创建的jar-with依赖项,不包含任何lib类或jar