Alternatively, we've created a custom assembly descriptor called src.xml in the src/assembly directory (see the Resources section for more information), we can tell the Assembly Plugin to use it instead: Again, note that we could specify multiple custom assembly descriptors here. Once you've configured the various descriptors and descriptorRefs for the assemblies you want the project to produce, it's time to determine how you want to build them. NOTE: Many other configuration options are available for the various mojos in the Assembly Plugin. While it's possible to assign the single goal to any phase of the build lifecycle, you should be careful to make sure the resources included in your assembly exist before that assembly is created. Note: Many other configuration options are available for the various goals in the Assembly Plugin. In this quick article we'll focus on packaging a Maven project into an executable Jar file.Usually, when creating a jar file, we want to execute it easily, without using the IDE; to that end, we'll discuss the configuration and pros/cons of using each of these approaches for creating the executable. Apache Software Foundation, For more information on writing your own assembly descriptor, read the. In order for this discussion to be useful, it's critical to cover two topics: configuration of the plugin - both inside the POM and, where possible, from the command line - and the different execution styles. Unfortunately, this currently means that binding the assembly mojo to the default lifecycle will cause Maven to execute the build twice - once for the main process, and once again in a forked lifecycle which is spawned by the assembly mojo itself. To bind the attached mojo to a project's build lifecycle, you can add this configuration (assuming you're using the jar-with-dependencies prefabricated descriptor): Then, to create a project assembly, simple execute the normal package phase from the default lifecycle: If instead you want to bind the directory-inline mojo to a project's build lifecycle - so you can construct a directory containing your assembly - you can add this configuration (assuming you're using the jar-with-dependencies prefabricated descriptor): As you've no doubt noticed, the Assembly Plugin can be a very useful way to create a self-contained binary artifact for your project, among many other things. To bind the single goal to a project's build lifecycle, you can add this configuration (assuming you're using the jar-with-dependencies prefabricated descriptor): Then, to create a project assembly, simple execute the normal package phase from the default lifecycle: When this build completes, you should see a file in the target directory with a name similar to the following: Notice the artifact classifier, between the end of the version and the beginning of the file extension, jar-with-dependencies. To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources ). In some cases, you may only want to create an assembly periodically; these mojos provide two ways to accomplish that goal. Sauf si vous avez besoin du "maven-assembly-plugin" pour des raisons autres que le réglage de la mainClass, vous pouvez utiliser le " maven-jar-plugin ' plugin. Currently, there are two basic approaches to building assemblies: as a dedicated build action, or bound to a phase of the normal build lifecycle. To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). 问题I have been trying for several days now to create an executable jar file for my muli-module maven project. Maven assembly jar execution Could not find or load main class Caused by: java.lang.ClassNotFoundException. Using this configuration, it's easy to configure the Main-Class attribute of the JAR manifest: If we add this configuration to the single goal example above and rebuild, we will see an entry like this in the META-INF/MANIFEST.MF file of the resulting JAR: For more information on advanced configuration for the Assembly Plugin, see the Resources section. You configure it as follows in your project's pom.xml: Note that the Assembly Plugin allows you to specify multiple descriptorRefs at once, to produce multiple types of assemblies in a single invocation. To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources). We can tell the Assembly Plugin to use that instead: Again, note that we could specify multiple custom assembly descriptors here. Beyond this, it's also possible to have the Assembly Plugin simply create an assembly directory for any given descriptor or descriptorRef, instead of creating archives. In most cases, the single goal should be bound to the package phase of the build. maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主页) The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive. For the sake of clarity, we'll cover configuration before execution. This is the id of the assembly descriptor used to create this artifact. At this point, the directory-oriented mojos - directory and directory-inline - do not support the configuration element. First, let's examine how we can build an assembly directly, as a process separate from the normal build lifecycle. Maven assembly plugin is not good in producing fat/uber jar, it may cause name conflict issue, it is better to use other Maven plugins like : Maven shade plugin solve this by using technique like class relocating. Active yesterday. The main advantage of producing an assembly in this way is to avoid producing it as part of your normal build process. maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主页) The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive. Viewed 19 times 0. At this point, only the jar and war assembly formats support the configuration element. The resultant jar is also called 'fat jar'. This is handled by the assembly:single goal. Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: [...] [...] maven-assembly-plugin [...] … This document is intended to provide instructions for using the maven-assembly-plugin. In this case, assemblies won't be produced when the normal build is executed, only in special circumstances. For example, imagine that our project produces a jar.