This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Using Own Directory Structure in Maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Using Own Directory Structure in Maven" Watch "Using Own Directory Structure in Maven" New topic
Author

Using Own Directory Structure in Maven

seenu akula
Greenhorn

Joined: Nov 23, 2009
Posts: 12
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

Joined: Jun 25, 2001
Posts: 15952
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

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

Joined: Jun 24, 2003
Posts: 3274
    
    5

And welcome to Javaranch!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
seenu akula
Greenhorn

Joined: Nov 23, 2009
Posts: 12
Thanks a lot Tim & Martijn for your quick reply

seenu akula
Greenhorn

Joined: Nov 23, 2009
Posts: 12
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

Joined: Jun 25, 2001
Posts: 15952
    
  19

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

Joined: Nov 23, 2009
Posts: 12
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.



[Thumbnail for dir_structure.JPG]

seenu akula
Greenhorn

Joined: Nov 23, 2009
Posts: 12
Sorry Tim I have referred you as Tom in last message.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

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

Joined: Nov 23, 2009
Posts: 12
Thanks Tim. Its working now. The problem is with the parent pom file.
 
wood burning stoves
 
subject: Using Own Directory Structure in Maven
 
Similar Threads
Ant javac task and subdirectories
Add multiple files in WEB-INF of war
Headfirst ch3 Beerselect submit button not working
Configuration issues with tomcat5
stateless endpoint, how to make soap-fault exeption rollback enabled