Migration from existing Java EE project to maven without changing directory layout - maven

I have seen many questions concerning this issue, but I'm new to this topic and I have to convert previously written project (standard, Eclipse Java EE project) into Maven.
My first problem is that I'm completely new to Maven. Second - I can't change the directory layout. And third - I'm running out of time.
Some of topics I've read covered few of my questions, but I need it clearer.
I have 3 modules connected with each other:
* Main one with catalogues: .settings, db-schema, EarContent,
* EJB with .settings, bin, build, ejbModule
* WEB with .settings, build, src, WebContent.
As far as I know (correct me if I'm wrong) there is just one 'mapping' when I have single catalogue with source code and it looks like this:
<build>
<sourceDirectory>ejbModule</sourceDirectory>
...
But what if I have two catalogues? I mean the WEB module - src and WebContent.
What else do I need to change if don't use standard directory layout?
What with the main module with EarContent? - There is no source code, but there is an -ds.xml file which (I guess) I have to put somewhere.
In main POM.xml I know that I have to add tags, but is there anything else I should do?
Sorry for (maybe) not precise and wide questions, but I've started today and I have to do it fast. So far I've found Sonatype site and managed to get one of their pdfs, but I'm reading it quite too slow and need 'some' help doing it. I've also downloaded the archetype for nexus repository and I'm trying to understand it.

Try to use add-source goal of build-helper-maven-plugin.

Related

Maven Archetype creation via Eclipse

I am willing to create an archetype which will be useful to create a lot of projects sharing the same architecture. I followed the maven guide and read some bloggers guides but even with these informations I am struggling.
I have some constraints for my projects :
All the project code is in a package which must be something like com.ei.app.project (app and project are vars I would like to set during the project generation)
I have dependencies I would like to be present in my POM when the project is generated
I have some scripts file with data (paths, app name...) and I would like to set them according to the project parameters, and if it is possible add additional parameters.
We don't use the official maven repo but set up another online repo. We have a strict security policy an whenever we have to add a lib into the repo it takes a lot of time for verifications.
How can I achieve this ? I tried several solutions but encountered a lot of errors. If you have a complete step-by-step guide in english or french that would be fantastic, but I would also like to understand how it works.
Many thanks for your help
Let me answer parts of your question.
From an example project, you can create an archetype by using archetype:create-from-project (https://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html).
You can supply a property file that will be used to replace actual values (like 1.0.0-SNAPSHOT) with references (like $version). All filtered files will be treated as velocity templates so that you can use $-type replacement.
Your repository restriction may be problem because you probably need dozens of artifacts to make the archetype plugin run.
I finally created a "base" project with all I need inside (libraries, main Vert.x class...), and developed a script to replace a template value (i.e __projectName__ ) in dir / file names and inside configuration / pom.
It's close enough to what we need and provide a cool replacement tool for my company, which will be used for multiple purposes.

Rename file for Nexus

Background: we are migrating an application and have to adopt some new structures so the autmatic installation process works at our customers site.
Until now we are using maven-classifiers to build 3 different flavours of the same module (say flavours A, B and C). The problem is the automatic installation process at our customers site can't handle this as we expect. While downloading from the nexus, the 3 artifacts overwrite each other and only the last is actually there.
There is absolutely no way, that we can fix this issue from the customer side (although it would be trivial!). Actually, our customer won't change absolutely anything on his site - we have no control whatsover of the enviornment on our customers site.
So the proposed solution to make this work, to deploy 3 artifacts with different artifactIds. I.e. modA, modB and modC
My question is: how to achieve this in the 'most elegant way'?
We don't want to restructure the whole project as truly triplicating the number of modules would be horrendous.
My ideas so far of which I'm not even sure if they would work:
Use antrun plugin to copy/rename files and generate the corresponding pom files from a template and then use deploy-file to upload to the nexus.
Using assemblies? How?
Creating new submodules with the corresponding pom files (and in there the GAV the costumer requires) inside each one of the modules which should be deployed, but each of these submodules would basically only copy the artifacts from targetA/app--, targetB/... and targetC/... This way I hope at least having a more or less clean deploy step (without using a deploy-file to deploy a WAR and a pom). The pom files would be minimal and viewed from the root-module we would still see only one module 'mod' and hide the ugliness inside this rather than having 3 modules 'modA', 'modB' and 'modC'. This way we would also decouple the devs-view and the deployments-view on the project. Devs could continue the way they are used to and integrators would take care of the 'putting things in the way the customer wants it'-part. Now here my question is: how can I create a maven project where the 'complete build' is actually nothing more than copying a war?
It is clear to me, that all these choices are horrible. If you know of the 'right way' to solve my problem I would really appreciate it. Otherwise I would really just like to know how to achieve the 'copying a war' part.

Maven site in gradle

Is there a plugin in gradle which can generate maven site similar thing? It would be great if it was compatible with current maven site apt format file.
It seems that there are two plugins, this and this. The first one was committed four years ago, I know nothing about the second. So it seems that these plugins will not be helpful.
I just wrote one as part of Gradle Fury. The primary plugin(s) (it's really just a collection of scripts) for Gradle-Fury is to enhance/fix many of the gradle short comings on publishing, android stuff, pom stuff, etc. Since there's pretty much no standard way for most things in gradle, we jam most of those configurations in the gradle.properties file. That said, the site plugin does depend on those settings to correctly stylize the site.
In short, to apply to your project...
put this in your root build.gradle file
apply from 'https://raw.githubusercontent.com/gradle-fury/gradle-fury/master/gradle/site.gradle'
Next edit your gradle.properties file and use this link as a template for your pom settings....
https://github.com/gradle-fury/gradle-fury/blob/master/gradle.properties
Create a src/site/ directory.
Make a src/site/index.md file as your home page
Copy/clone following files/folders from https://github.com/gradle-fury/gradle-fury/tree/master/src/site
css
images
img
js
template.html
Finally, build the site with gradlew site. Default output is to rootDir/build/site
Don't like the way it looks? (it looks like the Apache Fluido theme from the maven site plugin). Just edit template.html to meet your needs.
I'm currently working on a mechanism to bootstrap the site plugin which will remove a few of these steps, but that's what it is right now. More info and complete feature list is at the wiki
One last note, should run gradlew site after all of your check tasks, but it's not wired up to depend on it. Basically, anything that produces reports for your modules should be ran before site since it's aggregated into the site package, including javadocs and much more. The rest of the fury scripts help automate much of the painful configuration steps. Worth checking out (see the quality and maven-support plugins)
Disclaimer: I'm one of the authors.
Edit: site preview: http://gradle-fury.github.io/gradle-fury/
Edit: We just cut an updated version that makes manual creation of src/site and all the copy/clone tasks from the master repo unnecessary. Just run gradlew site while internet connected and it'll do the rest for you.

Maven war plugin copy arbitrary files

I apologize that this is surely basic maven/war plugin stuff, but I'm totally not a maven user. I just have to hack this one thing into a project that is maven based.
What I need to do is to copy an (essentially arbitrary) directory and files into the root of my war. I need them to appear as resources available via HTTP when the war deploys.
I cannot simply put them in the "right place" in the source tree. This is because the files in question are actually the source files of my project. I realize this is a bit odd, but this is a documentation project, and I need to show the source and the effect all in the same war.
So, in the general case, how would I configure the maven war plugin to copy a given directory, along with it's contents, to the root of my war? (BTW, I have tried to make sense of the documentation of this tool, but it seems to be predicated on so much understanding of maven that it feels like I'll never understand it without learning maven first, and I'm a bit too pressed for time to do that just now!)
Many TIA
Toby.
You could try:
use the copy-resources plugin. Use the plugin to copy your source files under target prior to when the war is packaged.
or, configure the maven-war-plugin to include additional resources.
Thanks Drew, that got me where I needed to go. Bottom line, I added the sample pom fragment from the link you gave for copy-resources to my pom.xml with the following changes:
<outputDirectory>target/${project.name}-${project.version}/sources ...
<directory>src/main/java ...
I copied this from the link you gave, then edited the element to point at src/main/java, which picked up my files, and the outputDirectory to the aggregate target/${project.name}-${project.version}/sources . I found that ${project.name} mapped to the project, and the version came from ${project.version}, which seemed to resolve the last little bits of issue.
Thanks again.
Toby

Where can I find updated and "unbloated" webapp archetypes for maven?

I'm pretty new to maven and I'm trying to find a good archetype for creating a webapp "starting point" for a Spring MVC project. I have been rtfm-ing, googling and installed many of the archetypes I've found in lists presented here on SO and other places, but I never found one fitting my needs.
Example 1: I installed org.apache.maven.archetypes -
maven-archetype-webapp, but it seems outdated, as it uses JRE 1.5,
JUnit 3.8.1 and also it's missing src/test/java, src/test/resources
and src/main/resources by default.
Example 2: Using eclipse, I created a new "Spring MVC Project" from "Spring Template
Project", which also set up Maven for me, but it installs loads of
stuff I'm not sure I even need.
I also tried some other archetypes, like from AppFuse and Cocoon, but the "bloating" in their basic webapp archetypes was even worse.
What I'm after is kind of what the maven-archetype-webapp is giving me, but an "updated" version that also includes the test and resource directories.
So I guess my question is two folded:
1. Is there an "updated" version of the maven-archetype-webapp archetype?
...and/or...
2. Is there a way for me, as a maven newbie, to create my own archetype that fits my needs?
... or have I totally been misunderstanding the concept of archetypes?
Is there an "updated" version of the maven-archetype-webapp archetype?
AFAIK, version 1.0 is the last version (and is not very up-to-date). BTW, it seems it doesn't define the source code level (so I guess 1.5 you have is coming from your IDE)
Is there a way for me, as a maven newbie, to create my own archetype that fits my needs?
Creating a new artifact is quite simple. Here are the details.
Is it so simple for a maven newbie ? Well, it depends... but according the quality of your post, it seems you understood the basics so yes, it should be easy to do.
Basically an archetype is nothing more than:
the target project structure you need (with some files like pom.xml, web.xml, ...)
a file describing the resources that need to be included in this structure.
Take a look at maven-archetype-webapp-1.0.jar (i.e. unzip it) and you will immediately understand why the directories are missing and from where junit-3.8.1 comes from.
Note: you will find the maven-archetype-webapp-1.0.jar in your maven repository. (Probably here : /.m2/repository/org/apache/maven/artifacts/maven-archetype-webapp/1.0/... but I didn't check)

Resources