Maven字符串替换文本Web资源 [英] Maven String Replace of Text Web Resources

查看:714
本文介绍了Maven字符串替换文本Web资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文本文件的Maven Web应用程序

I have a Maven web application with text files in


src / main / webapp / textfilesdir

src/main/webapp/textfilesdir

据我所知,在包装阶段,这个textfilesdir目录将被复制到

As I understand it, during the package phase this textfilesdir directory will be copied into the


target / project-1.0-SNAPSHOT

target/project-1.0-SNAPSHOT

目录,然后压缩成


target / project-1.0-SNAPSHOT.war

target/project-1.0-SNAPSHOT.war

问题

现在,我需要在target / project-1.0-SNAPSHOT / textfilesdir中对文本文件的内容进行字符串替换。然后必须在将textfilesdir复制到target / project-1.0-SNAPSHOT之后但在创建target / project-1.0-SNAPSHOT.war文件之前完成此操作。我相信这一切都是在打包阶段完成的。

Now, I need to do a string replacement on the contents of the text files in target/project-1.0-SNAPSHOT/textfilesdir. This must then be done after the textfilesdir is copied into target/project-1.0-SNAPSHOT, but prior to the target/project-1.0-SNAPSHOT.war file being created. I believe this is all done during the package phase.

如何将插件(可能是maven-antrun-plugin)插入包阶段来执行此操作。

How can a plugin (potentially maven-antrun-plugin), plug into the package phase to do this.

文本文件不包含要过滤的$ {property-name}等属性。字符串替换可能是唯一的选择。

The text files don't contain properties, like ${property-name} to filter on. String replacement is likely the only option.

选项


  1. 在创建WAR之前,在复制到target / project-1.0-SNAPSHOT目录后修改文本文件。

  1. Modify the text files after the copy into target/project-1.0-SNAPSHOT directory, yet prior to the WAR creation.

打包后,从WAR中提取文本文件,修改它们,然后将它们添加回WAR。

After packaging, extract the text files from WAR, modify them, and add them back into the WAR.

我在想这里还有另一种选择,我想念。有人想过吗?

I'm thinking there is another option here I'm missing. Thoughts anyone?

推荐答案

选项1不可行, prepare-package 太早了, package 为时已晚,所以我看不到你可以在哪里插入任何自定义工作。选项2是可行的但是痛苦的IMO。所以这里有一些更多的命题(全部基于AntRun和 ReplaceRegExp 和/或替换任务。)

Option 1 is not doable, prepare-package is too early, package is too late so I don't see where you could plug any custom work. Option 2 is doable but a painful IMO. So here are some more propositions (all based on AntRun and the ReplaceRegExp and/or Replace tasks).

解决方案1:


  1. 创建一个新文件夹,放置需要处理的文本文件。

  2. 将antrun插件绑定到 prepare-package 并将其配置为处理文件并将处理过的文件放在目标下的某个目录中(例如 target / textfilesdir )。

  3. 配置war插件以包含 target / textfilesdir 作为 webResource 。请参阅添加和过滤外部网络资源了解详情。

  1. Create a new folder where you put the text files that need to be processed.
  2. Bind the antrun plugin to prepare-package and configure it to process the files and put the processed files in some directory under target (e.g. target/textfilesdir).
  3. Configure the war plugin to include target/textfilesdir as a webResource. Refer to Adding and Filtering External Web Resources for the details.

解决方案2:


  1. 将antrun插件绑定到 prepare-package 并将其配置为处理 src / main / webapp / textfilesdir 并将处理过的文件放在 target / project-1.0-SNAPSHOT 中。

  2. 配置war插件以排除以前处理的文件。再次参考添加和过滤外部Web资源详情。

  1. Bind the antrun plugin to prepare-package and configure it to process the text files from src/main/webapp/textfilesdir and put the processed files in the target/project-1.0-SNAPSHOT.
  2. Configure the war plugin to exclude the previously processed files. Again, refer to Adding and Filtering External Web Resources for the details.

我想我会选择第二个解决方案。

I think I'd go for the second solution.

这篇关于Maven字符串替换文本Web资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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