Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用maven打包期间转换web.xml?_Maven_Maven 3 - Fatal编程技术网

如何在使用maven打包期间转换web.xml?

如何在使用maven打包期间转换web.xml?,maven,maven-3,Maven,Maven 3,我正在将一个ant脚本移植到maven,我一直在转换我的web.xml My web.xml在开发期间将以下安全约束设置为“无”,并将为生产服务器生成的war设置为“机密” <security-constraint> <web-resource-collection> <web-resource-name>HTTPSOnly</web-resource-name> <url-pattern>/*</

我正在将一个ant脚本移植到maven,我一直在转换我的web.xml

My web.xml在开发期间将以下安全约束设置为“无”,并将为生产服务器生成的war设置为“机密”

<security-constraint>
    <web-resource-collection>
      <web-resource-name>HTTPSOnly</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
我使用XSL脚本处理从ant调用的web.xml文件。我希望maven生成war文件,其中XSL已应用于web.xml,转换后的web.xml用于生成的war


我知道maven XSL插件和maven概要文件的概念,但我很难把它们放在一起,我不确定什么是正确的maven方式来处理这种情况

有很多方法可以实现这一点。可能最简单的方法是使用maven antrun插件并调用现有的ant任务


我知道的其他方法是使用变量/占位符和Maven过滤变量替换,看看:

有很多方法可以实现这一点。可能最简单的方法是使用maven antrun插件并调用现有的ant任务


我知道的其他方法是使用变量/占位符和Maven过滤变量替换,看看:

Maven的方法是使用过滤

下面是不使用xsl的常规web.xml筛选示例:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <webResource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <targetPath>WEB-INF</targetPath>
                        <filtering>true</filtering>
                    </webResource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>
如果您坚持使用xsl,您可以从以下基础上使用:


Maven的方法是使用过滤

下面是不使用xsl的常规web.xml筛选示例:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <webResource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <targetPath>WEB-INF</targetPath>
                        <filtering>true</filtering>
                    </webResource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>
如果您坚持使用xsl,您可以从以下基础上使用:


我用pom.xml为web应用程序设置了一个prod概要文件,其中包含以下插件,解决了我的问题。这对我来说是可行的,因为当项目导入到eclipse中时,我真的不希望发生任何花哨的事情,我希望一切都能在开发人员机器上开箱即用。下面没有显示,但我还添加了对NodeJS的调用,以便在生成源代码阶段使用RequireJS构建javascript前端

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>transform</goal>
            </goals>
            <configuration>
                <transformationSets>
                    <transformationSet>
                        <dir>src/main/webapp/WEB-INF</dir>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <stylesheet>src/main/webapp/WEB-INF/web.xsl</stylesheet>
                    </transformationSet>
                </transformationSets>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>target/generated-resources/xml/xslt/web.xml</webXml>
        <archiveClasses>true</archiveClasses>
        <warSourceExcludes>META-INF/context.xml</warSourceExcludes>
        <packagingExcludes>
            **/**/context.xml
        </packagingExcludes>
    </configuration>
</plugin>

我用pom.xml为web应用程序设置了一个prod概要文件,其中包含以下插件,解决了我的问题。这对我来说是可行的,因为当项目导入到eclipse中时,我真的不希望发生任何花哨的事情,我希望一切都能在开发人员机器上开箱即用。下面没有显示,但我还添加了对NodeJS的调用,以便在生成源代码阶段使用RequireJS构建javascript前端

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>transform</goal>
            </goals>
            <configuration>
                <transformationSets>
                    <transformationSet>
                        <dir>src/main/webapp/WEB-INF</dir>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <stylesheet>src/main/webapp/WEB-INF/web.xsl</stylesheet>
                    </transformationSet>
                </transformationSets>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>target/generated-resources/xml/xslt/web.xml</webXml>
        <archiveClasses>true</archiveClasses>
        <warSourceExcludes>META-INF/context.xml</warSourceExcludes>
        <packagingExcludes>
            **/**/context.xml
        </packagingExcludes>
    </configuration>
</plugin>