1. <legend id='W2Da4'><style id='W2Da4'><dir id='W2Da4'><q id='W2Da4'></q></dir></style></legend>
  2. <small id='W2Da4'></small><noframes id='W2Da4'>

    <tfoot id='W2Da4'></tfoot>
    • <bdo id='W2Da4'></bdo><ul id='W2Da4'></ul>

      <i id='W2Da4'><tr id='W2Da4'><dt id='W2Da4'><q id='W2Da4'><span id='W2Da4'><b id='W2Da4'><form id='W2Da4'><ins id='W2Da4'></ins><ul id='W2Da4'></ul><sub id='W2Da4'></sub></form><legend id='W2Da4'></legend><bdo id='W2Da4'><pre id='W2Da4'><center id='W2Da4'></center></pre></bdo></b><th id='W2Da4'></th></span></q></dt></tr></i><div id='W2Da4'><tfoot id='W2Da4'></tfoot><dl id='W2Da4'><fieldset id='W2Da4'></fieldset></dl></div>
    1. 将 jar 打包到具有分离的外部资源和依赖项的 dist 目录中

      Packaging a jar into a dist dir with separated external resources and dependencies(将 jar 打包到具有分离的外部资源和依赖项的 dist 目录中)

    2. <small id='JSgEC'></small><noframes id='JSgEC'>

      <legend id='JSgEC'><style id='JSgEC'><dir id='JSgEC'><q id='JSgEC'></q></dir></style></legend>
            <tbody id='JSgEC'></tbody>

            <i id='JSgEC'><tr id='JSgEC'><dt id='JSgEC'><q id='JSgEC'><span id='JSgEC'><b id='JSgEC'><form id='JSgEC'><ins id='JSgEC'></ins><ul id='JSgEC'></ul><sub id='JSgEC'></sub></form><legend id='JSgEC'></legend><bdo id='JSgEC'><pre id='JSgEC'><center id='JSgEC'></center></pre></bdo></b><th id='JSgEC'></th></span></q></dt></tr></i><div id='JSgEC'><tfoot id='JSgEC'></tfoot><dl id='JSgEC'><fieldset id='JSgEC'></fieldset></dl></div>

            • <bdo id='JSgEC'></bdo><ul id='JSgEC'></ul>

            • <tfoot id='JSgEC'></tfoot>
                本文介绍了将 jar 打包到具有分离的外部资源和依赖项的 dist 目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这就是我想要实现的目标 - 一个如下所示的 dist 目录(或 zip 文件):

                Here's what I'm trying to achieve - a dist directory (or a zip file) that looks like this:

                dist/
                |-- application-1.0.jar
                |-- conf/
                    |-- application.properties
                    |-- log4j.properties
                |-- lib/
                    |-- *.jar
                

                基本上:

                • 生成一个可执行的 jar(在清单中有适当的类路径)
                • 我想排除src/main/resources与jar自动打包,以便修改application.properties
                • 我想在lib/目录下有外部依赖
                • An executable jar is produced (with appropriate classpath in the manifest)
                • I want to exclude src/main/resources from being automatically packaged with the jar, so that application.properties can be modified
                • I want to have external dependencies in the lib/ directory

                我想出了一个解决方案,它使用带有附加到包阶段的插件的配置文件,但是使用程序集插件会是更好的解决方案吗?

                I came up with a solution using a profile with plugins attached to the package phase, but would using the assembly plugin be a better solution?

                推荐答案

                使用汇编插件的解决方案有几个部分:

                The solution using the assembly plugin has a few parts:

                • pom包括配置jar插件(maven-jar-plugin),配置组装插件(maven-assembly-plugin).
                • 在maven的打包阶段,调用jar插件构建应用jar.
                • 然后运行程序集插件,并将构建的 jar、资源和依赖项组合到程序集文件 (distribution-zip.xml) 定义的 zip 文件中.
                • The pom includes configuring the jar plugin (maven-jar-plugin), and configuring the assembly plugin (maven-assembly-plugin).
                • During maven's packaging phase, the jar plugin is called to construct the application jar.
                • Then the assembly plugin is run, and combines the constructed jar, resources and dependencies into a zip file as defined by the assembly file (distribution-zip.xml).

                在 pom 中,配置插件:

                In the pom, configure the plugins:

                <build>
                    <plugins>
                        <plugin>
                            <artifactId>maven-jar-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                <archive>
                                    <!-- Make an executable jar, adjust classpath entries-->
                                    <manifest>
                                        <addClasspath>true</addClasspath>
                                        <classpathPrefix>./lib/</classpathPrefix>
                                        <mainClass>com.acme.KillerApp</mainClass>
                                    </manifest>
                                    <!--Resources will be placed under conf/-->
                                    <manifestEntries>
                                        <Class-Path>./conf/</Class-Path>
                                    </manifestEntries>
                                </archive>
                                <!--exclude the properties file from the archive-->
                                <excludes>
                                    <exclude>*.properties</exclude>
                                </excludes>
                            </configuration>
                        </plugin>
                
                        <plugin>
                            <artifactId>maven-assembly-plugin</artifactId>
                            <version>2.2-beta-5</version>
                            <configuration>
                                <descriptors>
                                    <descriptor>${basedir}/assembly/distribution-zip.xml</descriptor>
                                </descriptors>
                            </configuration>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>single</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                ...
                

                汇编文件 distribution-zip.xml 的内容(感谢 Neeme Praks) 结合了创建的 jar、资源和依赖项:

                The contents of the assembly file distribution-zip.xml (with thanks to Neeme Praks) combines the created jar, resources and dependencies:

                <assembly>
                    <id>dist</id>
                    <formats>
                        <format>zip</format>
                    </formats>
                
                    <includeBaseDirectory>true</includeBaseDirectory>
                
                    <dependencySets>
                        <dependencySet>
                            <!--Include runtime dependencies-->
                            <outputDirectory>lib</outputDirectory>
                            <scope>runtime</scope>
                        </dependencySet>
                    </dependencySets>
                
                    <fileSets>
                        <fileSet>
                            <!--Get the generated application jar-->
                            <directory>${project.build.directory}</directory>
                            <outputDirectory>/</outputDirectory>
                            <includes>
                                <include>*.jar</include>
                            </includes>
                        </fileSet>
                        <fileSet>
                            <!--Get application resources-->
                            <directory>src/main/resources</directory>
                            <outputDirectory>conf</outputDirectory>
                        </fileSet>
                        <fileSet>
                            <!--Get misc user files-->
                            <directory>${project.basedir}</directory>
                            <outputDirectory>/</outputDirectory>
                            <includes>
                                <include>README*</include>
                                <include>LICENSE*</include>
                                <include>NOTICE*</include>
                            </includes>
                        </fileSet>       
                    </fileSets>
                </assembly>
                

                生成的可分发 zip 文件的创建方式类似于 target/killer-app-1.0-dist.zip

                The resulting distributable zip file is created like target/killer-app-1.0-dist.zip!

                这篇关于将 jar 打包到具有分离的外部资源和依赖项的 dist 目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <bdo id='ys78u'></bdo><ul id='ys78u'></ul>

                  <small id='ys78u'></small><noframes id='ys78u'>

                • <legend id='ys78u'><style id='ys78u'><dir id='ys78u'><q id='ys78u'></q></dir></style></legend>
                • <i id='ys78u'><tr id='ys78u'><dt id='ys78u'><q id='ys78u'><span id='ys78u'><b id='ys78u'><form id='ys78u'><ins id='ys78u'></ins><ul id='ys78u'></ul><sub id='ys78u'></sub></form><legend id='ys78u'></legend><bdo id='ys78u'><pre id='ys78u'><center id='ys78u'></center></pre></bdo></b><th id='ys78u'></th></span></q></dt></tr></i><div id='ys78u'><tfoot id='ys78u'></tfoot><dl id='ys78u'><fieldset id='ys78u'></fieldset></dl></div>
                    <tfoot id='ys78u'></tfoot>
                            <tbody id='ys78u'></tbody>