Automate custom war files using maven

2019-03-04 18:02发布

问题:

I know about maven war overlays, but they assume that the original war file is a maven project.

What if I only have access to the packaged war file and I need to modify it by adding new resources or updating few values in properties file using maven and push the new overplayed packaged war file to tomcat on a server?

Is it too complex to do this in maven?

If I install the war file in my repository does the maven build process automatically use it?

回答1:

It doesn't assume that the WAR is a Maven project, whatever that means, just that the WAR is a Maven artifact. You can install any WAR as an artifact, it does not matter how it was built. If you then declare a dependency to this artifact, you'll be able to overlay it. While it is easy to add and replace files (just create a normal web project structure containing the new files and the WAR plugin will do the rest), it is not easy to modify them. If you really wanted that, you'd have to run something like the replacer plugin after the original WAR is extracted but before the package phase of your project. It is also possible to download a (WAR) file instead of getting it from a repo by using some exotic plugins, but this is probably not something you should be doing as it blows away half the benefits of Maven.

As for deploying the newly-built application to a remote Tomcat, while doable using the Tomcat plugin, it is not something I would be doing from Maven. It is usually a job for a build server, like e.g. Jenkins, while the Tomcat plugin is more for local development and testing.