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 - maven

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.

Related

How can I exclude artifacts by packaging in maven-dependency-plugin:copy-dependencies

I'm working in a complex tomcat configuration where I'm using third party proprietary service that is distributed as WARs. In the servlet container I have 10 WARs deployed where only one is coded by us.
We are using maven to manage the project.
I'm declaring the third party WAR files in the POM with provided scope.
My issue comes when I try to use maven to deploy the system in a local testing server.
I'm using maven-dependency-plugin:copy-dependencies goal to copy the right artifacts in the right directories in the local serving tester.
I must copy JAR files in one directory and WAR files to a different directory. But maven is not differentiating the artifacts by packaging. So I end having the JARs mixed with the WARs in the destination directory. While I need to have two executions, one for WARs and one for JARs going to the right directory.
I have only being able to use a copy goal specifying every artifact to copy, but this is difficult to maintain if any developer adds a new dependency, the dependency must also be added to the right copy goal.
I will like to be able to use copy-dependencies goal but being able to indicate that I only want to copy a specific packaging.
Any idea on how I can manage to do that?
Thanks!
You can use -DexcludeTypes=war
https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#excludeTypes

How to convert alfresco ant based project in alfresco5 maven based?

I am using alfresco 4.1.3 having following project structure.
I am using the ant script to build project.
Now I want to convert this project into maven based alfresco5.
I have configured alfresco5 using all-in-one archetype and I am able to run it successfully. My questions are:
How can I convert my alfresco ant based project in alfresco5 maven based?
Do I need to add src files in repo or repo-amp?
Do I need to copy all share related files in share or share-amp?
Any help would be greatly appreciated!!!
Thanks in Advance.!!
That totally depends on the ant build setup. But one good guess is that you will have to put the files residing in the "Alfresco" folder of your old project into different subfolders of the repo-amp, and the same way around with the "Share" folder. Most files will go into those folders, you have to study the SDK-docs carefully to know into which folders the files will go. Depending of the nature of your extensions some files could go into the Share and Alfresco war-structure as well (additions to web.xml for example).
There are no "Swiss army knife" for that works for all cases here.
Good luck
Do the following things:
Create new project as maven project and provide group id (it's yours) artifact id as alfresco5 and version (ex:43.0.1-SNAPSHOT)
With this it creates maven based folder structure
src/main/java -> replace it with your src folder
3.src/main/resources ->add your Share, reference and Alfresco folders.
look at you lib directory..what ever .jar will be there you need to define it in dependencies under pom.xml
compile the whole project..if there are compilation errors then add required dependencies in pom.xml

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.

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

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.

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