views:

593

answers:

5

Is there any standard directory layouts for Java projects? What layout do you prefer most?

I'm asking about more complex layout than just 'src' and 'bin' in project's directory (i.e. where do you put your test classes, build configurations, etc.?).

Thanks in advance.

+2  A: 

I usually use /src for source code, /test or /tst for test code, /build for class files, /lib or /libs for dependencies, /dist for my JAR and libraries (so I can just compress the directory and distribute it without thinking), and /docs for documentation (including JavaDoc). My Ant build script goes in the directory that the ones I named are subdirectories of.

When I build, I create the JAR from /build and copy /lib and maybe /docs into /dist.

Thomas Owens
I don't think I forgot any major directories or file sets. If I did, let me know and I'll add where I put them. I don't have any major Java projects outside of work at the moment.
Thomas Owens
A: 

I use:

programming
  - distro
  - java
      - lib
      - src
          - com...
          - net...
          - org...
      - tools

And I compile classes side-by-side with the sources, and package from there to a subdirectory of distro.

Software Monkey
+1  A: 

Are you using any build tools? Like Maven for example? If not, you probably should - and in that case your directory layout would be predefined for you.

ChssPly76
... and in the particular case of Maven, you would be well advised not to stick with the predefined layout!
Stephen C
Care to elaborate? I'm not saying you need to follow it to the letter, but what's wrong with the overall layout?
ChssPly76
That's one reason why I don't like Maven at all.
duffymo
Ooops ... s/not//p ... I meant to say that "you would be well advised to stick with the predefined layout".
Stephen C
@duffymo "One reason" being what? Predefined layout? What's wrong with it?
ChssPly76
The layout for Maven does look a bit overengineered. Could you elaborate on why you think it's a good layout, other than that you have no choice.
Marcus Downing
Well advised? I think "forced" is the operative word, and I don't like being forced by something like a build tool. Just preference, but I'm not crazy about the src/main and src/test idiom. I usually just have /src and /test. I'd feel better if there was a way to specify preferences. Besides, Maven feels too heavy by half. I was able to grok Ant in a short time; not so with Maven. I'd prefer Ant and Ivy. It's something of an open source standard, but thank god it's not as well accepted elsewhere.
duffymo
"overengineered" - I agree with Marcus Downing.
duffymo
You do have a choice - you can change default Maven layout in project file. That said, separation between "main" and "test" hierarchies is completely logical - tests have their own resources and configuration files. Same goes for webapp (if applicable), java, resources and config under "main" - why shouldn't they be separated? I'm not arguing for use of Maven vs Ant/Ivy - if you don't understand or don't like it, don't use it. But I seriously don't get the "I didn't understand it so it sucks" approach.
ChssPly76
Voting +1 against all the anti-Mavite jackasses voting this down...
Nate
A: 

For web projects I usually use:

<project name>
  dev
    src
    lib
    www
    build.xml
  build
    www
    bin
  www

The www folder in src is the original. The www folder in build is where that gets combined with the contents of similar folders to produce what needs to be uploaded. The www folder outside is where I run a local copy, complete with temporary files and other such garbage. I have an ant script in build.xml to copy things around.

I'd like to know if there is any sort of standard.

Marcus Downing
And your tests go where?
ChssPly76
+1  A: 

You could take a look at Sun Developers Network - Project Conventions

OblongZebra