简体   繁体   中英

How do I create and run an executable jar with maven that has external dependencies?

I have a jar plugin but it's not running because it isn't including the external dependencies in the jar. I can't seem to figure out how to include these dependencies, I seem to be finding a bunch of different solutions that conflict with each other for some reason. I ideally would like it to run on systems without the need for any special maven commands.

create maven pom.xml with

<packaging>jar</packaging>

By default it should not pack into your jar all dependent libraries.

<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>

What you are looking for is to build an über-jar. The Maven Shade plugin can do that - http://maven.apache.org/plugins/maven-shade-plugin/ . It even allows for renaming of classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM