This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Maven archetype with custom layout  RSS feed

 
Greenhorn
Posts: 8
Debian IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning,

I am trying to create a Maven archetype. I have the following custom project layout:

src/main/java => is called src
src/test/java => is called src-test
src/test/resources => is called test-resources

I can not change this layout as it is used on every and each of our projects. So my question is: do you know how to use such a custom layout in an archetype, please?

Regards
 
Saloon Keeper
Posts: 10249
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the problem? Have you taken a look at the archetype descriptor reference?

https://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html
 
Glen Lang
Greenhorn
Posts: 8
Debian IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just read it, thanks. But I can't figure out how to instruct Maven with my layout. Here is the error:



That's a weird error! The 'lowerCaseProjectName' is a property managed by my archetype, but when using a standard layout I don't have this error and all is fine. And when using our in-house layout I have it... And I can't afford to change our layout as it is used by more than 100 projects...
 
Stephan van Hulst
Saloon Keeper
Posts: 10249
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand you don't want to use the standard layout just to be consistent with the other projects, but I question this kind of pointless bureaucracy.

Anyway, show us the layout of your archetype and what you've done in the archetype descriptor.
 
Glen Lang
Greenhorn
Posts: 8
Debian IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's go!

Here is the layout of my archetype-generating project:





Here is the content of the archetype-metadata.xml file:




Here are the relevant parts of the pom.xml from the archetype-generating project (BatchArchetype):




Here is the layout of the generated archetype (under BatchArchetype/target/generated-sources/archetype/src/main/resources/archetype-resources):




Here is the error message that I get when issuing "mvn install" from the base directory of the generated archetype (repeated several times):




And lastly, here is the output of the console when launching the archetype generation:





The last line is repeated several times.

Sorry for this very long message, and thanks in advance.
 
Glen Lang
Greenhorn
Posts: 8
Debian IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works!

This SO post helped me: https://stackoverflow.com/questions/39080569/change-package-property-in-maven-archetype

I had a misunderstanding about the "packaged = true" parameter which this post helped me to understand! I removed my sources from 'fr/backoffice/batch', moved them to the root of 'src/' and then, using the syntax "package ${package}.mypackages", it all works well.

Thanks a lot, guys!
 
Bartender
Posts: 20770
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After due reflection, I think that actually setting up an archetype with non-standard directory layout isn't really a good idea.

I'll admit that one of the first things that kept me from adopting Maven initially was its insistence on its own special directory structure. The second thing being that unlike Ant, you couldn't see what the rules being executed were.

But I've since learned to accept it. For a couple of reasons.

1. It's consistent. Every (standard) Maven project in the world has the same directory structure. That means that if I pass a project to someone in Outer Mongolia, they will instantly know where to find stuff without wasting time searching.

2. It's simple. The very thing that put me off about Maven - the fact that it does things by "magic" instead of explicitly-written rules means that you don't waste time setting up build rules (or in this case, POM overrides). The fact that the magic tools don't have to be told where the source, resources and other build inputs are located is a further benefit.

3. It's authoritative. Several new build systems have been developed since Maven that act on the same general philosophy. I'd expect them to also follow the same general organization, thus reducing their learning curves and helping support their own adherence to the first 2 items listed above.

I'm NOT saying to turn the shop upside down and re-code all the builds willy-nilly. But it would be a good idea to migrate to standard directory structure as new builds are created (which is what archetypes are for). It's not so burdensome to have 2 sets of rules rather than 1 while in transition, and if you already had a consistent structure, it shouldn't even be that hard to put together a migration script to be used as projects come up for maintenance.
 
Glen Lang
Greenhorn
Posts: 8
Debian IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Food for thoughts, thanks. I do agree with you, unfortunately, I wasn't given a choice... You know how things go...
 
Tim Holloway
Bartender
Posts: 20770
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Glen Lang wrote:Food for thoughts, thanks. I do agree with you, unfortunately, I wasn't given a choice... You know how things go...



4. It's less expensive. Because anyone familiar with Maven knows where to look for things in the project, you don't have to spend time (== $) teaching new hires and temps your quirky project standards. And they don't have to spend time (== $) remembering where to put/dig for stuff when you need them to work on projects.
 
I do some of my very best work in water. Like this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!