eclipse - 在部署/条件部署之前检查 war 文件

标签 eclipse maven tomcat cargo

当使用 cargo 部署到远程服务器时,我想检查 cargo 或 maven 生成的 war 是否按预期过滤了它的属性文件。

中间的某个阶段应该针对某些字符串测试 war 中的属性文件,以便部署或停止部署。

有内置的 cargo 来实现这一点吗?

最佳答案

不确定您指的是什么属性文件,因此我假设您指的是典型的 java *.properties 文件。

无论如何,我相信你应该使用:maven-enforcer-plugin 它的目标是:enforce 因为这是 Maven 中强制执行某些条件的常用方法(插件使用术语:rule) 来实现。

我认为您在这里有更多选择。

选项 1

也许您可以使用以下方法检查打包到您的 war 的优先级:

maven-property-plugin - 目标:read-project-properties ( http://mojo.codehaus.org/properties-maven-plugin/usage.html )

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>???</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>your_file_to_check.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

你应该在哪里:

然后执行 maven-enforcer-plugin 目标:enforce 和规则:requireProperty ( http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html )

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
      <execution>
        <id>enforce-property</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireProperty>
              <property>your_property_to_check</property>
              <message>You must set a your_property_to_check property!</message>
              <regex>regex</regex>
              <regexMessage>violation txt</regexMessage>
            </requireProperty>               
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
    </executions>
  </plugin>

哪里:

  • your_property_to_check 应该替换为真实的以及
  • regex 应该被定义

选项 2

如果那不可行并且您想检查war 文件中的属性,您可能需要编写自己的规则

这应该不是什么大问题,因为 java 在其标准 API 中具有 zip 读取和属性文件加载功能。要了解如何编写自定义规则,请参阅:http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

顺便说一句。我很想知道为什么有人要在每次部署时检查某些属性?您的输入(您过滤的属性文件)是动态生成/更改的吗?否则,一旦您检查它是否有效,我怀疑您是否需要它。

关于eclipse - 在部署/条件部署之前检查 war 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18199911/

相关文章:

java - Google Cloud Platform Java - Maven 部署目标错误的项目

java - 在 pom.xml 中传递 VM 参数

java - 如何使用 Maven 制作 jar of jar

eclipse - 如何使用 Eclipse 和 HTC Desire HD 在 PhoneGap 应用程序中显示 console.log() 输出?

Eclipse IDE 中的 Eclipse 服务器问题

eclipse - 在 JDK 中运行 Eclipse?

bash - 脚本在 crontab 中无法正常工作,但在我手动运行时可以正常工作

android - 如何阻止 ADT Logcat View 在 Eclipse 中自动弹出?

java - 二进制部分写入错误

java - 摆脱 Tomcat 中的 Spring 日志