Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Own Directory Structure in Maven

 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friendz,

I am new to Maven. I have a directory structure like this
Web------------>btech------>jsps
                   |--->META-INF
                   |--->WEB-INF----> classes---> class files & resource files
                   |-->btech-----> struts-config.xml & validation.xml
                   |-->web.xml

This structure should not be changed. Is there any way I could change the standard directory structure to my own structure? Please Suggest. If you can help me with a sample pom file for this directory structure. It would be great. Thanks in advance.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18024
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can override maven's directory architecture, but there are 2 reasons why you shouldn't.

1. It's a lot of trouble. You have to go in an manually override all the locations in your POM.

2. It makes the project non-standard. One of Maven's big selling points is that anyone can start working on a Maven project fairly quickly, because they don't have to figure out where the various project components are located like they do with less strictly-organized systems like Ant's.

I'll admit that I'm not terribly in love with Maven's directory organization myself, but I've learned to live with it because of the advantages it brings.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18024
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, you can keep your directory structure almost completely intact just by placing it in a WAR project's src/main/webapp directory. Since you're using Struts, however, you might want to move some of the resource definitions to src/main/resource where plugins can build the config information dynamically using the resources as models.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to Javaranch!
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Tim & Martijn for your quick reply

 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to use the Maven standard directory Structure, but I am getting duplicate files(every file twice) in war

I am getting Classes folder, Module2 folder and Module2 folder contains classes folder again in Web-inf. Please help me.

My Pom file is some thing like this:

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18024
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only questionable thing I see in your POM is that appears you're choosing a source compile level of 1.2, and Java 1.2 is so ancient, I'd recommend going to at least 1.4. But that wouldn't cause this problem.

If you haven't looked at the docs for the Maven WAR plug-in, you should do so, since they describe the differences between a generic Maven project structure and a WAR project.

Here are some things to note, however:

1. src/main/webapp contains an image of the static parts of your WAR, from its root on down. It doesn't contain the WAR root directory itself, however. In other words, if your app is named "myapp", it's not src/main/webapp/myapp/WEB-INF, it's src/main/webapp/WEB-INF. And if I said src/main/resources, I'm sorry. My memory is a dangerous thing to trust.

2. Note that I said static resources. Don't compile classes and put them into src/main/webapp/WEB-INF/classes unless they're externally compiled library resources. Maven will compile your project's sources and put them in the final WAR (target/myapp). In most cases, if you have a src/main/webapp/WEB-INF/classes directory at all, it will only have static configuration files like the log4 properties file in it, not class files.

The more complicated you've made things, the more likely you're doing something you shouldn't. Maven expects to be able to do all the basic WAR-building functions itself with minimal outside help.
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,

I have done in the same way you have mentioned, but the problem still exists.
Struts, validation xmls are created twice in WEB-INF/classes/src/main/webapp/WEB-INF/Iyear and WEB-INF/Iyear folders.
The folder structure I have created is as in the attached image.
dir_structure.JPG
DIR structure
[Thumbnail for dir_structure.JPG]
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Tim I have referred you as Tom in last message.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18024
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:


You should produce a target/Module2 directory that's properly organized. If not, you may need to post the Maven console log.
 
seenu akula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim. Its working now. The problem is with the parent pom file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic