maven2:从 WAR 中排除目录

发布于 2024-09-19 19:02:49 字数 932 浏览 6 评论 0原文

我尝试 this 排除整个目录(${basedir}/src/main/webapp/webscripts) 来自我的 WAR 文件,但失败了。怎么了?

这不起作用:

<configuration>
   <webResources>
      <resource>
       <directory>${basedir}/src/main/webapp/webscripts</directory>
       <excludes>
        <exclude>**/*.*</exclude>
       </excludes>
      </resource>
   </webResources>
</configuration>

这也是:

<configuration>
   <webResources>
      <resource>
       <directory>${basedir}/src/main/webapp</directory>
       <excludes>
        <exclude>**/webscripts</exclude>
       </excludes>
      </resource>
   </webResources>
</configuration>

有人可以帮忙吗?

I tried this to exclude whole directory (${basedir}/src/main/webapp/webscripts) from my WAR file but it failed. What is wrong?

this doesn't work:

<configuration>
   <webResources>
      <resource>
       <directory>${basedir}/src/main/webapp/webscripts</directory>
       <excludes>
        <exclude>**/*.*</exclude>
       </excludes>
      </resource>
   </webResources>
</configuration>

this too:

<configuration>
   <webResources>
      <resource>
       <directory>${basedir}/src/main/webapp</directory>
       <excludes>
        <exclude>**/webscripts</exclude>
       </excludes>
      </resource>
   </webResources>
</configuration>

Can anybody help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

眼角的笑意。 2024-09-26 19:02:49

您的两种解决方案都没有帮助,因为它们会添加额外的资源,然后将其停用。默认复制webapp源文件夹,没有资源机制。

停用其中一部分的机制是通过 参数,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warSourceExcludes>webscripts/**</warSourceExcludes>
    </configuration>
</plugin>

Both of your solutions wouldn't help, as they would add an additional resource that is then deactivated. The webapp source folder is copied by default, without the resource mechanism.

The mechanism to deactivate a part of that is through the <warSourceExcludes> parameter, like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warSourceExcludes>webscripts/**</warSourceExcludes>
    </configuration>
</plugin>
仄言 2024-09-26 19:02:49

warSourceExcludes 似乎不只是被重命名为packagingExcludes

warSourceExcludes:复制 warSourceDirectory 内容时要排除的以逗号分隔的标记列表。

packagingExcludes:打包前要从 WAR 中排除的以逗号分隔的令牌列表。该选项可用于实现
精简的 WAR 用例。

有一个很大的区别:使用packagingExcludes,令牌被完全排除在最终的war文件中。使用 warSourceExcludes,将 war 目录复制到 war 文件时会忽略标记。
因此,例如,如果令牌存在于 webappDirectory 中,则在使用 warSourceExcludes 时它们不会被忽略,但在使用 packagingExcludes 时则会被忽略。

以及一个有效的语法示例:

<warSourceExcludes>**/${project.artifactId}/**</warSourceExcludes>

warSourceExcludes seems not to have been just renamed packagingExcludes.

warSourceExcludes: The comma separated list of tokens to exclude when copying the content of the warSourceDirectory.

packagingExcludes: The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement
the skinny WAR use case.

There is a big difference: With packagingExcludes, the tokens are completely excluded from the final war file. With warSourceExcludes, the tokens are just ignored when copying the war directory into the war file.
As a result, if the tokens are present in the webappDirectory for example, they will not be ignored when using warSourceExcludes but will be when using packagingExcludes.

And a working syntax example:

<warSourceExcludes>**/${project.artifactId}/**</warSourceExcludes>
倾听心声的旋律 2024-09-26 19:02:49

在版本 2.1-alpha-1 中,它被错误地命名为 warSourceExcludes。正确的参数是 packagingExcludes

使用示例 (从 WAR 中排除 WEB-INF/statics/ 文件夹):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <warName>searchservice-web</warName>
        <packagingExcludes>WEB-INF/statics/</packagingExcludes>
    </configuration>
</plugin>

In version 2.1-alpha-1, this was incorrectly named warSourceExcludes. The right parameter is packagingExcludes

Example of usage (excludes WEB-INF/statics/ folder from WAR):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <warName>searchservice-web</warName>
        <packagingExcludes>WEB-INF/statics/</packagingExcludes>
    </configuration>
</plugin>
垂暮老矣 2024-09-26 19:02:49

项目结构

为了删除源文件,我在 Maven 中使用了以下配置

 <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
      <packagingExcludes>
        eb-app/app/**,eb-app/node_modules/**,eb-app/public/**,eb-app/server/**,eb-app/tests/**,eb-app/tmp/**,eb-app/vendor/**,eb-app/*
      </packagingExcludes>
    </configuration>
  </plugin>

Project Structure

Inorder to remove the source files i have used the below configuration in maven

 <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
      <packagingExcludes>
        eb-app/app/**,eb-app/node_modules/**,eb-app/public/**,eb-app/server/**,eb-app/tests/**,eb-app/tmp/**,eb-app/vendor/**,eb-app/*
      </packagingExcludes>
    </configuration>
  </plugin>
放我走吧 2024-09-26 19:02:49

有一个场景,我必须排除两个可以由 *scripts 匹配的文件夹,并且它们位于资源文件夹中。第一个困惑是是否以 src/main/resources/*scripts 或 WEB-INF/classes/*scripts 的形式提供排除值,即预编译结构或后编译结构。

提供 /** 以使整个目录从 war 文件中排除非常重要。就我而言,*scripts/**

这是最终有效的配置:

    <packagingExcludes>WEB-INF/classes/*scripts/**</packagingExcludes>

Had a scenario where I had to exclude two folders which could be matched by *scripts and they were in the resources folder. The first confusion was whether to provide the exclude value as src/main/resources/*scripts or as WEB-INF/classes/*scripts, i.e. pre or post compilation structure.

Was much important to provide /** to get the entire directory being excluded from the war file. In my case, *scripts/**.

Here is the final configuration which worked:

    <packagingExcludes>WEB-INF/classes/*scripts/**</packagingExcludes>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文