maven assembly plugin jar main class

However, when I try to run this jar file I get "Could not find or load main class src.main.java.com.domain.Mainclass" (I have changed the name domain and MainClass for my company's privacy sake) I have searched for days and none of the obvious tips seem to work. 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. NOTE: Many other configuration options are available for the various mojos in the Assembly Plugin. 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. This document is intended to provide instructions for using the maven-assembly-plugin. 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. In some cases, you may only want to create an assembly periodically; these mojos provide two ways to accomplish that goal. If you're using one of the prefabricated assembly descriptors, you just tell it which one; if you're using a custom assembly descriptor, you give it the path to the descriptor. To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources ). I have been trying, for several days now, to create an executable jar file for my muli-module maven project, sadly I have had no luck on doing it. For more information on writing your own assembly descriptor, read the. However, if your assembly doesn't require binaries, or if you need to use one assembly as input for another, you may need to change this. 问题I have been trying for several days now to create an executable jar file for my muli-module maven project. Active yesterday. 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. Note that a single invocation of the Assembly Plugin can actually produce assemblies from multiple descriptors, allowing you maximum flexibility to customize the suite of binaries your project produces. This ensures the assembly archives are made available for installation and deployment, and that they are created during the release of your project. If you want to use a custom assembly descriptor, you configure the path to your descriptor using the / parameter. To handle archiving this version of Maven Assembly Plugin uses Maven Archiver 3.5.0. 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. To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources). All rights reserved. However, once you've created this self-contained jar, you will probably want the ability to execute it using the -jar JVM switch. For more information, see the examples section or the plugin parameter documentation. Note that a single invocation of the Assembly Plugin can actually produce assemblies from multiple descriptors, allowing you maximum flexibility to customize the suite of binaries your project produces. At this point, only the jar and war assembly formats support the configuration element. Because many assemblies will contain compiled classes and other binaries, it's reasonable to assume that the package phase will be required to ensure those binaries exist and have been tested. Additionally, it's possible to specify a mixture of descriptors and descriptorRefs within the same configuration. For a maven S W project that features "jar" packaging, we can specify the main class for the MANIFEST.MF file by specifying it in our pom.xml, as shown here: 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. At this point, the directory-oriented mojos - directory and directory-inline - do not support the configuration element. Now I get a ClassNotFoundException. I have a spring-boot project where all integration tests are in a separate module that launches the application module using spring-boot-maven-plugin during the integration-test phase and runs the package against it. 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. For more information, see the examples section or the plugin parameter documentation. The Apache Software Foundation. Maven one-jar plugin, add the dependency jar file directly into project jar, and loads it with custom class loader. Getting started with the Assembly Plugin is pretty simple. For the sake of clarity, we'll cover configuration before execution. 现在在Java工程中使用Maven已经是非常常见的配置。而对于Maven工程默认产生的Jar却不是可执行的,尤其在你创建了一个桌面应用程序后,不能直接执行是致命的。于是在本文中,我简单记录下如何配置使得Maven工程构建产生可执行的Jar,这里主要就是对Main-Class和Class-Path的配置。 This is handled by the assembly:single goal. 2002-2006 Apache Software Foundation, For more information on writing your own assembly descriptor, read the. We can tell the Assembly Plugin to use that instead: Again, note that we could specify multiple custom assembly descriptors here. Note: Many other configuration options are available for the various goals in the Assembly Plugin. 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. If we want to create an assembly binary that includes our project's dependencies, we can take advantage of one of the Assembly Plugin's prefabricated descriptors, as follows: Note that the Assembly Plugin allows you to specify multiple descriptorRefs at once, to produce multiple types of assemblies in a single invocation. However, once you've created this self-contained JAR, you will probably want the ability to execute it using the -jar JVM switch. Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: If we add this configuration to the attached mojo 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 can build an assembly directly by executing: 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. The attached and directory-inline mojos are functional counterparts of the mojos discussed above, except that they are meant to bind into the default build lifecycle. To handle filtering this version of Maven Assembly Plugin uses Maven Filtering 3.1.1. © Apache Maven Assembly plugin allows to create an executable jar which includes all its dependencies within it. In JavaS W, an executable jarW file specifies its main class in the MANIFEST.MF file in that jar file. By contrast, the attached mojo assumes that the build has already produced project binaries or whatever else it needs prior to building the assembly 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. [Java]Maven Assembly Pluginで実行可能(Executable)なjarを作成する 使い方 Javaプログラムをコマンドラインから実行するには、依存するライブラリを全てまとめて実行可能なjarファイル(Executable jar)を作るのが便利です。 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. The resultant jar is also called 'fat jar'. To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). Getting started with the Assembly Plugin is pretty simple. If you want to use one of the prefabricated assembly descriptors, you configure which descriptor to use with the / parameter. This is the id of the assembly descriptor used to create this artifact. Maven assembly jar execution Could not find or load main class Caused by: java.lang.ClassNotFoundException. 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. 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. This construct worked fine until it was upgraded to 1.4.0.RELEASE. When the assembly is created it will use the assemblyId as the artifact's classifier and will attach the created assembly to the project so that it will be uploaded into the repository in the install and deploy phase. For the sake of clarity, we'll cover configuration before execution. In most cases, the single goal should be bound to the package phase of the build. The main advantage of producing an assembly in this way is to avoid producing it as part of your normal build process. 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. 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. 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. For example, imagine that our project produces a jar. Spring-boot-maven-plugin> = 1.4.0 jar structure changes. For example, imagine that our project produces a JAR. To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). Existe-t-il un moyen d'inclure toutes les dépendances DANS le jar généré en exécutant l'objectif jfx: jar pour le plugin javafx maven? NOTE: Invoking the assembly and directory mojos will cause Maven to build the project using the normal lifecycle, up to the package phase. In most cases, you'll want to make sure your assemblies are created as part of your normal build process. This is the id of the assembly descriptor used to create this artifact. Once you've configured the various descriptors and descriptorRefs for the assemblies you want the project to produce, it's time to build them. 方法二:使用maven-assembly-plugin插件打包 When the assembly is created it will use the assemblyId as the artifact's classifier and will attach the created assembly to the project and will be uploaded into the repository on an install and deploy goal. Ask Question Asked yesterday. 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. The assembly mojo forces a package phase build to execute, in order to guarantee the availability of project binaries. Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: [...] [...] maven-assembly-plugin [...] … If we want to create an assembly binary that includes our project's dependencies, we can take advantage of one of the Assembly Plugin's prefabricated descriptors. 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. Currently, there are two basic approaches to building assemblies: as a dedicated build action, or bound to a phase of the normal build lifecycle. First, let's examine how we can build an assembly directly, as a process separate from the normal build lifecycle. Copyright ©2002–2020 To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources). Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: Because they depend on correct binding to the lifecycle in order to gain access to the files required by your project assembly, the attached and directory-inline mojos require the user to have much more intimate knowledge of the build process. Additionally, it's possible to specify a mixture of descriptors and descriptorRefs within the same configuration. 现在在Java工程中使用Maven已经是非常常见的配置。而对于Maven工程默认产生的Jar却不是可执行的,尤其在你创建了一个桌面应用程序后,不能直接执行是致命的。于是在本文中,我简单记录下如何配置使得Maven工程构建产生可执行的Jar,这里主要就是对Main-Class和Class-Path的配置。 Using this configuration, it's easy to configure the Main-Class attribute of the JAR manifest: 指定了Main-Class,有了依赖包,那么就可以直接通过java -jar xxx.jar运行jar包。 这种方式生成jar包有个缺点,就是生成的jar包太多不便于管理,下面两种方式只生成一个jar文件,包含项目本身的代码、资源以及所有的依赖包. You can construct an assembly directory directly from the command line by executing: When completed, you should see a directory structure similar to this: If you need to ensure that assemblies are produced whenever your project builds, or when a particular profile is activated (also useful for configuring other plugins during this special process), then the following two mojos are probably what you're looking for. Alternatively, we've created a custom assembly descriptor called src.xml in the src/assembly directory (see the Resources section for more information). Viewed 19 times 0. 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.

Griechische Sängerin Kreuzworträtsel, Lidl Holzkohle Preis, Mundschutz Kaufen Rewe, Schlafstörungen Bei Kindern, Der Kleine Prinz Zitate Traurig, Samsung Symbole Statusleiste Telefonhörer, Herz Los Wincent Weiss Lyrics,