Advice on project structure

Hi. I've been trying out intellij idea for a couple of days now (just updated to version 7 m1), and have run into a couple of questions/dilemmas as for how I'm going to structure my projects. I've previously mostly used pure editors like emacs, and therefore thought it wise to seek advice on this forum to avoid getting some bad habbits from the start =)

My main question is really on how its best to structure your code/projects in turn of folders and placement of different items, for example the libraries/jars that your code depends on? As an example Im currently working on a project that utilizes the spring framework, and I need the spring jars as both runtime and compile time dependencies. I've so far created a folder named 'lib' under my content root (and made idea ignore the folder), placed the needed jars there, and then added them as module libraries (similar to how I have usually done it when manually handling the project structure). This however feels somwhat wrong, since these libraries are now "part of the content". Would it be better to make some central "repository" folder on my computer, place all the frameworks I ever use there, and then reference them at that location, or what is common practice in this area? Does this change if I someday (as I hope I will :) ) start using some sort of SCM?

Thanks for the help

8 comments

Something like the following works well.


A central place might sound nice but leads to confusion and version problems.
It also prevents the project from being self-contained.

0

did you give a look at maven "standardized" layout ?

As it is growing more and more of a standard it might be a good idea

0

If not the maven layout, maybe Maven or Ivy to maintain your library dependencies outside of your project.

0

We have used a central (CVS) to maintain our libraries. CVS would look something like:

CVSroot
-lib
- -struts
- - -v1.2.4
- - -v1.2.9
- - -v2.06
- -commonsLang
- - -v...
-myProject
- -web

Both parts of the CVS tree are checked out. If someone adds a new library, I update my CVS project and I have it to use also.

The IntelliJ project maintains the link of what libraries I use via global library declarations. I declare Struts 1.2.9 once. Then I link it into any project that needs it. If I need to change from Struts 1.2.9 to Struts 2.0.6, I change the declaration. The global libraries take care of which jars/src/javadoc files my project now references.

The only thing better than this is Maven, but I am not keen on being forced to use their directory layout when I only want their dependency management (which is super cool). IVY is an alternative to Maven dependency management, but it did not have all that I wanted (automatic sources and javadoc download) the last time I looked at it.

0

You might consider following the structure mandated by maven. This will ensure that the growing number of maven users will recognize the project structure, and it will make it ease for you to start using maven should you wish to do so.

I use maven to manage dependencies and to build releases of the project. During development I use the internal idea build facility and have found it to work very well.

Start by setting up your maven project, then use the >mvn idea:idea plugin command to have maven generate your idea project / module files for you. You will automatically get the appropriate library references to your project libraries (you don't need your own lib folder), and idea will compile to the maven target folder.

- Torsten

0

Here is how I setup all my projects (non-j2ee):

root
--dist
--build
--lib
--src
-


java
-


java code here (in packages of course)

Lib holds all the jar files needed for the project. If I have jar files needed at build time but not runtime I usually create a build-lib directory (stuff like XDoclet for J2EE projects).

I went to a Java User's Group meeting about Maven once and instead of actually seeing it in action (what you would expect at a user's group meeting) I got a mind-numbingly boring 2 hour bullet point presentation about the wonders of Maven...that has left a sour taste in my mouth about Maven so I have never looked at it again. The presentation was by a Maven developer so I figured we could have at least got a demo...don't tell me Maven is better than ANT via bullet points for two hours and then don't show me Maven in action...grrr.

0

if you add a directory in IDEA and putting some files there, can the project still be compiled by Maven?

What is the best practice now with IDEA 7 M2:

1) use mvn idea:idea to create a project then IDEA uses it?
2) use IDEA to import the project using the preference(create temporary modules)?

Thanks,

A.C.

0

For me, mvn (or at least: maven) idea:idea didn't work with the latest EAP build, since it assumed my project was a 'standard java project', which it wasn't.

Importing the pom.xml did the trick, which (for me) worked much better.

0

Please sign in to leave a comment.