Are conventions for file structures needed in java?

  • Thread starter The Abrasive Sponge
  • Start date
T

The Abrasive Sponge

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. :)
 
B

Bryce

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.
 
F

Frank

The said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top