Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maven archetype "webapp-javaee6" question

 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
The Maven (I am using version 3.0.3) archetype "webapp-javaee6" doesn't create any test folder.
Also the WEB-INF/META-INF folders are not pre-created.

How would I test my application?
I have created a "test" folder under src/main but my test class is not getting invoked.

What am I missing here?

Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sujoy Choudhury wrote:I have created a "test" folder under src/main but my test class is not getting invoked.

The Maven directory structure assumes you are using src/test/java for your JUnit tests.

Also check your effective pom to make sure surefire or failsafe or there (depending on whether you have unit or integration tests.)
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne. That helped. Now my Test class is getting invoked.

My question is:
Why didn't Maven create those test folders automatically?
But Maven did create test folders for simple "jar" kind of projects.
But for "webapp-javaee6" and "war" type it didn't.

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use an archetype to create a project, then you get only what the designers of the archetype have provided. I have often found that many Java EE archetypes don't include the test directory structure. But there is nothing that says you can't create the directory yourself. My best suggestion is to create your own archetypes that contain everything you want. That's what I do, then I get a POM with all the settings that I want, a lot of boilerplate code, and lots of other things that I typically add to any of my web projects, all at the push of a button.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter for your response.

As per Maven's idea of "Convention over Configuration" why would Maven let developers decide where would they want the test folder?
These should be fixed as per Maven.

It's not a big deal, but anyway, thanks for your reply.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Maven you can move any of the folders to different locations. But you do so at your own peril because some plugins are not as good as looking up the configured location, instead relying on the default location.

Also, the absence of a test directory doesn't mean that something is amiss. Perhaps the archetype authors assumed that it is too difficult (or not possible) to write unit tests for that kind of web app (yeah, bad assumption). There are a lot of other conventional directories that are also missing from most archetypes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic