简体   繁体   English

如何防止 Maven 在 Struts2 应用程序中替换 ${id}

[英]How to prevent Maven from replacing ${id} in a Struts2 application

I develop a Java application on Struts2.我在 Struts2 上开发了一个 Java 应用程序。 We were previously building using Ant, and are preparing to transition towards Maven.我们之前使用 Ant 构建,并准备过渡到 Maven。

When I run mvn package , all instances of ${id} in struts.xml were getting replaced by com.appname:appname:war:localhost-SNAPSHOT in the /target folder (which contains the build output).当我运行mvn packagestruts.xml${id}所有实例都被/target文件夹(包含构建输出)中的com.appname:appname:war:localhost-SNAPSHOT替换。

We ended up with a lot of broken redirections.我们最终得到了很多损坏的重定向。

For example, this is what was originally in /src :例如,这是最初在/src

<action name="doaddadmin" class="dashboardaction.DoAddAdmin">
   <result name="ERROR">/pages/error.jsp</result>
   <result type="redirectAction">
      <param name="actionName">manageadmins</param>
      <param name="id">${id}</param>
   </result>
</action>

But it became like this in /target :但它在/target变成了这样:

<action name="doaddadmin" class="dashboardaction.DoAddAdmin">
   <result name="ERROR">/pages/error.jsp</result>
   <result type="redirectAction">
      <param name="actionName">manageadmins</param>
      <param name="id">com.appname:appname:war:localhost-SNAPSHOT</param>
   </result>
</action>

My pom.xml currently looks like:我的pom.xml目前看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- Version attributes will be updated by automated Github Workflow -->
    <groupId>com.appname</groupId>
    <artifactId>appname</artifactId>
    <version>${revision}</version>
    <packaging>war</packaging>

    <name>appname</name>
    <description>AppName Platform</description>
    <url>https://github.com/appname/platform-appname</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <revision>localhost-SNAPSHOT</revision>
    </properties>

    <profiles>
        <!-- Localhost environment -->
        <profile>
            <id>localhost</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <config.livemode>false</config.livemode>
                <config.web_url>http://localhost:8081/</config.web_url>
                <config.log4jfile>${sys:catalina.base}/logs/appname-%d{yyyy-MM-dd}.%i.log</config.log4jfile>
            </properties>
        </profile>
    </profiles>

    <repositories>
        <repository>
            <id>javaxt.com</id>
            <url>http://www.javaxt.com/maven</url>
        </repository>
        <!-- Our custom packages are hosted here -->
        <repository>
            <id>github-appname</id>
            <name>GitHub AppName Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/appname/platform-appname</url>
        </repository>
    </repositories>

    <dependencies>
        <!-- ...other dependencies -->

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.5.2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <pluginManagement>
            <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <artifactId>maven-project-info-reports-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
    <distributionManagement>
        <repository>
            <id>github-appname</id>
            <name>GitHub AppName Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/appname/platform-appname</url>
        </repository>
    </distributionManagement>
</project>

How do I suppress Maven from automatically replacing all instances of ${id} in struts.xml ?如何禁止 Maven 自动替换struts.xml${id}所有实例?

You probably need to deactivate resource filtering as described here:您可能需要按照此处所述停用资源过滤:

https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM