如何从Web项目创建战争和震撼? [英] How to create a war and jar from a web project?

查看:60
本文介绍了如何从Web项目创建战争和震撼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven Web项目,其包装为"war".程序包将生成确认为war格式的war文件.但是,我喜欢将项目打包为"jar"以及默认的"war"格式.因此,我正在尝试使用"Maven jar"插件来实现这一目标.我正在使用以下jar插件配置.

I have a maven web project that has packaging as "war". the package generates war file that confirms to war format. But, i like to package the project as a "jar" as well along with the default "war" format. So, I am trying to use "maven jar" plugin to achieve that. I am using the following jar plugin configuration.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-a-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                <includes>
                    <include>../../src/main/webapp/**</include>
                    <include>**/*</include>
                </includes>
            </configuration>
        </plugin>

"package"命令产生一个jar文件,其中包含类和"resources"文件夹的内容,而war文件产生一个适当的"war"文件.

The "package" command produces a jar file that contains the classes and the contents of 'resources' folder and war file produces a proper 'war' file.

但是jar文件中不包含'src/main/webapp'的内容. 如何使用jar插件将src/main/webapp的内容包含在jar中?

But the contents of 'src/main/webapp' are not included in the jar file. How to include the contents of src/main/webapp in the jar using the jar plugin?

推荐答案

通常 Maven war:war 提供了以下两个重要参数:-

Normally the Maven war:war provides 2 significant parameter as the following: -

1 archiveClasses

是否将为webapp中的类创建JAR文件.使用此可选配置参数,将将编译后的类 存档到一个JAR文件中,然后将 classes目录从网络应用程序中排除. 默认值为:false. 用户属性为:archiveClasses.

Whether a JAR file will be created for the classes in the webapp. Using this optional configuration parameter will make the compiled classes to be archived into a JAR file and the classes directory will then be excluded from the webapp. Default value is: false. User property is: archiveClasses.

2 attachClasses

是否应该将类(即WEB-INF/classes目录的内容)作为附加工件附加到项目.默认情况下,其他工件的分类器为类".您可以使用<classesClassifier>someclassifier</classesClassifier>参数进行更改.

即使这是提供 Maven War Plugin 的功能,不将src/main/webapp包括到创建的jar文件中.然后,您可以考虑 Maven组装插件

Even this is a feature provides the Maven War Plugin, this does not include the src/main/webapp to that created jar file. Then you may consider the Maven Asssembly Plugin

用于Maven的程序集插件的主要目的是允许用户将项目输出及其依赖项,模块,站点文档和其他文件聚合到一个可分发的存档中.当前,它可以创建以下格式的发行版:

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. Currently it can create distributions in the following formats:

  1. zip
  2. tar
  3. tar.gz
  4. tar.bz2
  5. jar
  6. dir
  7. 战争
  8. 以及已为ArchiveManager配置的任何其他格式

通过使用组装描述符,您可以过滤某些分发文件包含和排除工件等等.这意味着您可以使用任何必需的内容/资源来创建自己的存档.

By using the Assembly Descriptors, you can Filtering Some Distribution Files and Including and Excluding Artifacts and so on. This means you are able to create your own archive with any required contents/resources.

如果您想在您使用 Maven Jar插件时使用,我提到过.它还提供以下内容:-

If you would like to use the Maven Jar Plugin as you've mentioned. It also provides the following:-

  1. 包含/排除jar工件中的内容
  2. 要从项目中创建其他附加的jar工件

使用页面会为您提供更多信息.

The usage page will give you further information.

我希望这会有所帮助.

这篇关于如何从Web项目创建战争和震撼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆