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. 现在在Java工程中使用Maven已经是非常常见的配置。而对于Maven工程默认产生的Jar却不是可执行的,尤其在你创建了一个桌面应用程序后,不能直接执行是致命的。于是在本文中,我简单记录下如何配置使得Maven工程构建产生可执行的Jar,这里主要就是对Main-Class和Class-Path的配置。 Getting started with the Assembly Plugin is pretty simple. For example, imagine that our project produces a jar. Apache Software Foundation, For more information on writing your own assembly descriptor, read the. 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. This construct worked fine until it was upgraded to 1.4.0.RELEASE. 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. 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. In some cases, you may only want to create an assembly periodically; these mojos provide two ways to accomplish that goal. 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. 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. [Java]Maven Assembly Pluginで実行可能(Executable)なjarを作成する 使い方 Javaプログラムをコマンドラインから実行するには、依存するライブラリを全てまとめて実行可能なjarファイル(Executable jar)を作るのが便利です。 This is handled by the assembly:single goal. In JavaS W, an executable jarW file specifies its main class in the MANIFEST.MF file in that jar file. 指定了Main-Class,有了依赖包,那么就可以直接通过java -jar xxx.jar运行jar包。 这种方式生成jar包有个缺点,就是生成的jar包太多不便于管理,下面两种方式只生成一个jar文件,包含项目本身的代码、资源以及所有的依赖包. However, once you've created this self-contained jar, you will probably want the ability to execute it using the -jar JVM switch. 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. The main advantage of producing an assembly in this way is to avoid producing it as part of your normal build process. This is the id of the assembly descriptor used to create this artifact. 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. Apache Maven Assembly plugin allows to create an executable jar which includes all its dependencies within it. Currently, there are two basic approaches to building assemblies: as a dedicated build action, or bound to a phase of the normal build lifecycle. Ask Question Asked yesterday. NOTE: Many other configuration options are available for the various mojos in the Assembly Plugin. At this point, the directory-oriented mojos - directory and directory-inline - do not support the configuration element. 方法二:使用maven-assembly-plugin插件打包 2002-2006 First, let's examine how we can build an assembly directly, as a process separate from the normal build lifecycle. Active yesterday. Additionally, it's possible to specify a mixture of descriptors and descriptorRefs within the same configuration. 问题I have been trying for several days now to create an executable jar file for my muli-module maven project. To handle archiving this version of Maven Assembly Plugin uses Maven Archiver 3.5.0. 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. Getting started with the Assembly Plugin is pretty simple. Additionally, it's possible to specify a mixture of descriptors and descriptorRefs within the same configuration. 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. In this case, assemblies won't be produced when the normal build is executed, only in special circumstances. 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. Alternatively, we've created a custom assembly descriptor called src.xml in the src/assembly directory (see the Resources section for more information). 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. 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. 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. In most cases, you'll want to make sure your assemblies are created as part of your normal build process. 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. 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使用描述(拷自 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. The Apache Software Foundation. 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. Viewed 19 times 0. To accommodate this, the Assembly Plugin supports configuration of an element which is identical to that supported by the maven-jar-plugin (see Resources). © Copyright ©2002–2020 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. We can tell the Assembly Plugin to use that instead: Again, note that we could specify multiple custom assembly descriptors here. If you want to use one of the prefabricated assembly descriptors, you configure which descriptor to use with the / parameter. 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. In most cases, the single goal should be bound to the package phase of the build. 现在在Java工程中使用Maven已经是非常常见的配置。而对于Maven工程默认产生的Jar却不是可执行的,尤其在你创建了一个桌面应用程序后,不能直接执行是致命的。于是在本文中,我简单记录下如何配置使得Maven工程构建产生可执行的Jar,这里主要就是对Main-Class和Class-Path的配置。 NOTE: Invoking the assembly and directory mojos will cause Maven to build the project using the normal lifecycle, up to the package phase. Spring-boot-maven-plugin> = 1.4.0 jar structure changes. For example, imagine that our project produces a JAR. This document is intended to provide instructions for using the maven-assembly-plugin. 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. 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 identical to that supported by the maven-jar-plugin (see Resources ). 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. The assembly mojo forces a package phase build to execute, in order to guarantee the availability of project binaries. 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. This document is intended to provide instructions for using the maven-assembly-plugin. At this point, only the jar and war assembly formats support the configuration element. Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). Using this configuration, it's easy to configure the Main-Class attribute of the JAR manifest: 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. For the sake of clarity, we'll cover configuration before execution. 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. Now I get a ClassNotFoundException. 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. 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. All rights reserved. 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. 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. For the sake of clarity, we'll cover configuration before execution. For more information on writing your own assembly descriptor, read the. 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. 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. To handle filtering this version of Maven Assembly Plugin uses Maven Filtering 3.1.1. Maven assembly jar execution Could not find or load main class Caused by: java.lang.ClassNotFoundException. 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: 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. For more information, see the examples section or the plugin parameter documentation. The resultant jar is also called 'fat jar'. This ensures the assembly archives are made available for installation and deployment, and that they are created during the release of your project. 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. To accommodate this, the Assembly Plugin supports configuration of an element which is handled by maven-archiver (see Resources). Maven one-jar plugin, add the dependency jar file directly into project jar, and loads it with custom class loader. Using this configuration, it's easy to configure the Main-Class attribute of the jar manifest: [...] [...] maven-assembly-plugin [...] … If you want to use a custom assembly descriptor, you configure the path to your descriptor using the / parameter. 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: Many other configuration options are available for the various goals in the Assembly Plugin. 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. 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.

.

Manuellsen Net Worth, Wie Findet Ihr Den Namen Emily, Fabelhafte Tierwesen 2 Netflix, Michelle Dockery Größe, Flieger Grüß Mir Die Sonne Kinderlied, Drama Lyrics Drake, Demokratie Im Antiken Griechenland, Pia A320 Crash,