使用maven打包期间如何转换web.xml? [英] How to transform web.xml during packaging with maven?
问题描述
我正在将一个ant脚本移植到maven,而我仍然无法转换web.xml.
I am porting an ant script to maven, and I am stuck on transforming my web.xml.
我的web.xml在开发期间将以下安全性约束设置为NONE,对于为生产服务器产生的战争设置为CONFIDENTIAL.
My web.xml has the following security constraint set to NONE during development, and to CONFIDENTIAL for the war that is produced for the production server.
<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.
I use an XSL script to process web.xml file which is called from ant. I want maven to produce war file where the XSL has been applied to the web.xml and the transformed web.xml is used in the generated war.
我了解Maven XSL插件和Maven概要文件的概念,但是我正努力将所有这些放在一起,而且我不确定哪种Maven正确的方式来处理情况.
I know about the maven XSL plugin and the concept of maven profiles but I am struggling to put it all together and I am not sure what the right maven way is for dealing with situation.
推荐答案
我通过为Web应用程序使用pom.xml设置产品概要文件(其中包含以下插件)解决了我的问题.这对我有用,因为当将项目导入eclipse时,我真的不希望发生任何事情,并且我希望一切都可以在开发人员机器中直接使用.它未在下面显示,但我还添加了对NodeJS的调用,以在generate-sources阶段使用RequireJS构建javascript前端.
I solved my problem my setting up a prod profile with the pom.xml for the web app, with the following plugins in it. This works for me because when the project is imported into eclipse I really don't want anything fancy to happen and I want everything to work out of the box the developer machine. It is not shown below but I also added a call to NodeJS to build the javascript front end using RequireJS at the generate-sources phase.
<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>
这篇关于使用maven打包期间如何转换web.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!