Copy static resources (js and css) from a war dependency to Grails application's web-app directory. - maven

I have a project in Grails 2.1.3 and I'm trying to copy static resources like javascripts and css files from a war dependency to my Grails application's web-app/ directory. I'm trying to achieve something like war overlay. I tried generating the pom and using overlay feature of maven-war-plugin but it doesn't seem to work. Please, suggest a solution.

You could download the WAR file, then extract the contents with WinZip/WinRAR/7zip (or even with command line).
Then just copy over the files you need into your project's web-app directory.
This is, of course, assuming that you only need to copy these files over once, and not every time the app is run.

Related

Maven: how to deploy updated resources?

I am having trouble getting a good work flow using Maven for a webapp.
My context.xml fragment points to the target/MY_WEB_APP folder and so I would like a quick way to get modified resource files into that folder.
My resource files are in src/main/resources and they get copied to target/classes when I run Maven resources:resources. However unless I run a full build I don't get those files in the target/MY_WEB_APP folder. The full build takes a couple of minutes and I only want to copy the modified resource files.
All of the resources are classpath resources and are hot swappable as the frameworks can be set to auto-reload. An example is the Struts config files that are auto-reloaded on each request as I have set struts.devMode=true. Hence if I can get it into the correct location then I don't need to do a full build.
Currently I have a text editor that has the open resource file target/MY_WEB_APP/WEB-INF/classes/my-resource.xml and I manually copy the modified file from my IDE into the editor. This is obviously a very, very silly way to work and there must be a better way.
How can this be done without the manual copy and paste?

Merge i18n properties file in maven overlay plugin

I have two web application projects in place, Project A and Project B. Project B has war dependency on Project A. Both projects have messages.properties files to handle i18n. However, the location of properties is same for both the projects. I am using maven war overlay plugin to overlay files of Project A on to Project B. If files are in the same location for these two projects, maven will not override Project B's files and leave them as is. However, this leads to maintenance problems as new text for i18n has to be added in messages.properties of both the web applications.
Is there a way to tell maven war overlay plugin to merge the properties files at the time of packaging? The logic of not overriding files when already present serves us well otherwise.
You should be able to achieve this with the Maven Cargo plugin outputting an uberwar.
http://cargo.codehaus.org/Merging+WAR+files
It doesn't know how to merge properties files out of the box, but it's super easy to implement a custom merger, all you need to do is implement org.codehaus.cargo.module.merge.MergeProcessor, and have it available on the classpath.
You probably just want to write a simple merger that can concatenate files together, unless you have duplicate properties then you might need to do something a little more fancy.

Location for 3rd party component that will be used during the build (gradle)

We have one project that reuses 3rd party war (it's shindig-server-2.0.2.war if anyone asks:). This war currently sits in project root and the current ant tasks unzips it into some temp folder, performs several changes (like applying fixes, modifies the web.xml etc.) and finally build the war from our sources and the war content. This 3rd party is checked into the source repo.
We are migrating to gradle. Where should we put this file in Maven directory structure?
It does not look it belongs to /src/main/resources as it is not packed withing the artifcat; also, imho it does not belong to /src, too. Should we have a /lib/resources folder in root where we could store such files?
I don't think the Maven directory structure defines a place for local dependencies, and since this is a Gradle build, it doesn't really matter either. I wouldn't put it under src, but lib sounds fine.

Can i have a build goal that excludes from a WAR static files (.js, .css, images) and another build goal to export these static files

I am trying to get Maven to exclude from a Tomcat bound WAR static files as these will be served via Apache, and yet another build goal to package these static files so that i can deploy them separately to Apache.
Exclude resources by configuring your pom accordingly, http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html, maven-resources-plugin provides for that.
Assemblies are also an option.
As for exporting the files, I'd call it a second artifact of the same project which is not healthy as it breaks modularity, How to Create Two JARs from One Project (…and why you shouldn't).
This looks like a classic case of a multi module project.
One module for your static files (that you can pack as a jar or as a zip)
Second module for the rest of your code
As #patrungel suggested, don't mix them in the same module.
I hope this helps.

Using Maven 3, how do I overwrite a file defined in one of the dependencies?

I have a multi-module Java EE application including a module for the web archive.
The WAR declares a dependecy on another WAR which provides a general purpose CSS.
I'd like to overwrite the provided CSS in my local WAR to add some specific behaviour.
So I copied the CSS from the dependency and placed it in the very same directory in my local WAR (being src/main/webapp/css/file.css).
I assumed Maven to merge these files, so my changes eventually become visible.
However, after deploying the application I still end up with the general purpose version provided by the dependency.
Is there any solution / plugin to fix this?
What you probably need is Maven's overlay feature which can merge 2 war projects:
http://maven.apache.org/plugins/maven-war-plugin/overlays.html

Resources