Are conventions for file structures needed in java?

Discussion in 'Java' started by The Abrasive Sponge, Oct 11, 2004.

  1. Ok I have been doing java for a while. But I am thinking I may have
    unfortunately started off the wrong way. Maybe. Outerlying file
    structures have no convention. Seems that the open source community is
    the driving force to one convention that seems to be the norm. I would
    like to know if there is a website that talks about the conventions
    normally used. If not I believe one needs to be developed.

    Currently the way I do it. I have a development folder, and in this
    development folder I have my customers. Within the customers I have the
    projects that I am doing for them.


    For example:


    <Root>
    |- development
    | |- customerA
    | |- customerB
    | |-webAppA
    | | |-build
    | | |-build.xml
    | | |-data
    | | |-Pojo.java
    | | |-servlets
    | | |-listeners
    | | |-dao or entity
    | | |-actions
    | |-jnlpAppB
    | | |-sales
    | | |View.java
    | | |Model.java
    | | |Controller.java


    This is a kind of a sample of what I do, and my organization. Of
    course, my classpath would contain
    <Root>/development/customerB/webAppA/data,
    <Root>/development/customerB/webAppA/servlets, etc. I use packages
    extensively but in the above example I omitted them in the diagram for
    clarity. As you see my packaging is not really consistent.

    Now I am thinking I am doing this the wrong way. I am wanting to do
    commit to a standard. Would any of these be a correct convention
    (below) of organizing file structures or do you have better ideas for this?

    <Root>
    |- development
    | |- customerA
    | |- customerB
    | |-webAppA
    | | |-build <- would a build file go here?
    | | | or just the resulting deliverable?
    | | |-src <- source files only?
    | | |-actions <--technology driven
    | | |-servlets
    | | |-listeners
    | | |-lib <- libraries other jars needed etc?
    | |

    <Root>
    |- development
    | |- customerA
    | |- customerB
    | |-webAppA
    | | |-build <- would a build file go here?
    | | | or just the resulting deliverable?
    | | |-src <- source files only?
    | | |-sales <---use case driven
    | | |-manager
    | | |-customer
    | | |-lib <- libraries other jars needed etc?
    | |


    The next question is how do I organize the source file packages?
    For example, say I am making a web app. Do you package like this?

    com/mycorp/sales/servlet/Something.java

    where the use case is before the technology or vice versa

    com/mycorp/servlet/sales/Something.java?

    I guess I am asking is what is the convention for package naming in any
    environment is it technology driven or use case driven? Do you have
    your own methods of packaging?

    Let me absorb your thoughts. :)
    The Abrasive Sponge, Oct 11, 2004
    #1
    1. Advertising

  2. The Abrasive Sponge

    Bryce Guest

    On Mon, 11 Oct 2004 12:28:40 -0600, The Abrasive Sponge
    <> wrote:

    >Ok I have been doing java for a while. But I am thinking I may have
    >unfortunately started off the wrong way. Maybe. Outerlying file
    >structures have no convention. Seems that the open source community is
    >the driving force to one convention that seems to be the norm. I would
    >like to know if there is a website that talks about the conventions
    >normally used. If not I believe one needs to be developed.


    There are some conventions, but no "standard" one. The one I prefer is
    this:

    <root>
    |- src/
    |- |- java/
    |- |- tests/
    |- |- resources/
    |- build/
    |- |- classes/
    |- |- tests/
    |- |- gen-src/ <== For generated src
    |- docs/
    |- lib/
    |- build.xml
    |- build.properties
    |- webroot/ <== For Web based stuff

    My build script deploys required files to webroot... Tomcat docbase
    points to webroot.

    >Currently the way I do it. I have a development folder, and in this
    >development folder I have my customers. Within the customers I have the
    >projects that I am doing for them.



    Welll. The above example is for a single project. Above that, I
    usually have similar to what you do:

    <root>
    |- project1
    |- project2
    ....


    >The next question is how do I organize the source file packages?
    >For example, say I am making a web app. Do you package like this?
    >
    >com/mycorp/sales/servlet/Something.java
    >
    >where the use case is before the technology or vice versa
    >
    >com/mycorp/servlet/sales/Something.java?


    I do a combination of both.
    com/mycorp/project/Something.java
    com/mycorp/project/web/SomethingServlet.java

    >I guess I am asking is what is the convention for package naming in any
    >environment is it technology driven or use case driven? Do you have
    >your own methods of packaging?


    I guess I'm coping out by saying it depends. If something is always
    going to be web based, such as servlets, ec. Then I have a subpackage
    for web stuff.

    --
    now with more cowbell
    Bryce, Oct 11, 2004
    #2
    1. Advertising

  3. The Abrasive Sponge

    Frank Guest

    The Abrasive Sponge wrote:
    > Ok I have been doing java for a while. But I am thinking I may have
    > unfortunately started off the wrong way. Maybe. Outerlying file
    > structures have no convention. Seems that the open source community is
    > the driving force to one convention that seems to be the norm. I would
    > like to know if there is a website that talks about the conventions
    > normally used. If not I believe one needs to be developed.
    >
    > Currently the way I do it. I have a development folder, and in this
    > development folder I have my customers. Within the customers I have the
    > projects that I am doing for them.

    *snip*
    > Now I am thinking I am doing this the wrong way. I am wanting to do
    > commit to a standard. Would any of these be a correct convention
    > (below) of organizing file structures or do you have better ideas for this?
    >
    > <Root>
    > |- development
    > | |- customerA
    > | |- customerB
    > | |-webAppA
    > | | |-build <- would a build file go here?
    > | | | or just the resulting deliverable?
    > | | |-src <- source files only?
    > | | |-actions <--technology driven
    > | | |-servlets
    > | | |-listeners
    > | | |-lib <- libraries other jars needed etc?
    > | |


    Personally, i find the netbeans (4.0) default web-app structure fair enough:

    <project>
    |-- build.xml <- Goes in project root directory.
    |-- build <- All contents/structure for the .war, built/copied
    to a temp folder named 'web'. (Nothing you want to keep in here, it's a
    just temp folder, deleted along with 'dist' before a clean build.)
    |-- dist <- .war file
    |-- src <- Anything .java in here. Duplicate the package
    structure from the examples of whatever framework you're using.
    |-- web <- jsp/html/images/whatever
    |- META-INF
    |- WEB-INF
    |- lib <- My libs are all stored externally, but this would
    be the place to put them? Or better make it a root dir?

    As for keepin track of projects / customers, I'd say go for Subversion
    (http://subversion.tigris.org/). I prefer one project each repository
    myself.

    I'm fairly new to the whole j2ee thing, so take this with a grain of
    salt or two. May wery well be talking out of my ass here.

    -Frank
    Frank, Oct 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    493
    Lasse Reichstein Nielsen
    May 22, 2005
  2. Thomas Nick
    Replies:
    0
    Views:
    1,864
    Thomas Nick
    Jun 13, 2005
  3. Neil Zanella
    Replies:
    9
    Views:
    409
    Jeffrey D. Smith
    Oct 16, 2003
  4. tweak
    Replies:
    14
    Views:
    2,769
    Eric Sosman
    Jun 11, 2004
  5. Alfonso Morra
    Replies:
    11
    Views:
    703
    Emmanuel Delahaye
    Sep 24, 2005
Loading...

Share This Page