如何使用maven从打包的webapp中排除类 [英] How to exclude classes from a packaged webapp with maven

查看:390
本文介绍了如何使用maven从打包的webapp中排除类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何过滤/ target / [webapp] / WEB-INF / classes中的/ target / classes中的某些类?我希望它们编译成/ target / classes /但不会在最后的战争中。

How can I filter certain classes in /target/classes from going into /target/[webapp]/WEB-INF/classes? I want them compiled into /target/classes/ but not in the final war.

推荐答案

这些类是什么?如果它们用于测试,您可以在src / test / java中指定它们,然后在测试 - 编译阶段将它们编译为目标/测试类,但不会包含在最终的战争中。

What are these classes for? If they are for testing, you can specify them in src/test/java, they will then be compiled into target/test-classes in the test-compile phase, but won't be included in the final war.

如果它们不是用于测试而且不包括在战争中,也许它们应该被重构为另一个项目,因此你可以将它指定为依赖项(也许是提供 范围,因此它们不会被部署。

If they aren't for testing and aren't to be included in the war, perhaps they should be refactored into another project so you can specify it as a dependency (perhaps with "provided" scope so they won't be deployed.

作为参考,您可以配置战争以在打包时包含和排除资源

For reference you can configure the war to include and exclude resources when packaging.

以下示例将包含所有jpgs但从image2子文件夹中排除资源:

The following example will include all jpgs but exclude resources from the image2 sub folder:

    <configuration>
      <webResources>
        <resource>
          <!-- this is relative to the pom.xml directory -->
          <directory>resource2</directory>
          <!-- the list has a default value of ** -->
          <includes>
            <include>**/*.jpg</include>
          <includes>
          <excludes>
            <exclude>**/image2</exclude>
          </excludes>
        </resource>
      </webResources>
    </configuration>

参见 war插件文档了解更多详情。

这篇关于如何使用maven从打包的webapp中排除类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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