Java/Linux Den

Monday, January 09, 2006

J2EE Project: Setting The Development Environment

So, in this post, we will be organizing our project development environment.Doing this properly will safe us alot of stress during deployment,testing,error/logic corrections and redeployemnt. Do we really have to save all our works directly inside the web container, it could be done during learning, when you want to quickely deploy a jsp page or even servlet to see the result. But you should never do this in the real world. Ok, let's quickely, look at the advantage of properly setting up this so called Development environment.

1. One can easilly compile all the project codes with a single javac command.

2. User define import statement are resolved easily.

3. The compiler can be used to generate file hierachy for our compiled classes.

4. Provides an easy means of moving our compiled codes to deployment environment.

This are my personal advantages, you are free to add your.


So let try and make out a file structure for our app. (Again, we might need to change this, as we move along but let wait to see how many changes, we will have to make)

Let call the project ums ( User management system).For linux user, let make our home directory the starting point and for windows user C:\. So, we create a project folder like this; please windows user should not forget to change / with \.


/your_home_dir/project ---- linux

C;\project ----- windows

Next let create the ums directory. Now the project directory is our reference point be you a linux or window user.

/project/ums

Now where will our source codes and compiled code go into. No problem, let's do that.

/project/ums/src ------ source codes

/project/ums/classes ---- compiled code (very interestings happen here)

What of packages, this was one of the most defficult aspect of java to get right but the understanding is very easy.

We are going to have a DbConnect class, that handles the connection to MySQL Database. So it will make sense to have db package.What of the servlets that will handle all the web logic,that's another package. So let's create the two packages.( Sorry, forgot to explain what are packages ?). Packages provide a way of arranging our source codes that is mapped to our computer file system. More on that later. So our source file structure should be like this.


/project/ums/src/db ----- for all Database relelated source codes.

/project/ums/src/web ------ for all servlet source codes.


What about the compiled codes, where will they go ? Do worry, there is a way the compiler can help us, but only if we tell him to generate the structure for us. Most cases, the compiler generated packages are less prown to error(if any at all) during deployment. Do not forget that all the codes, we want in the db directory, must be specified in the source code using the package statemant.We will say more on this later. But let see the advantages of properly formed development file structure.

To compile for example the DbConnet.java

javac -d classes -classpath classes;/home/mimoh/jakarta-tomcat-5.0.25/common/lib/servlet-api.jar:
src/db/DbConnect.java


So what we are telling the compiler the followings;

- d classes:

Here we are asking the comoiler to dump all the compiled codes into the classes directory. Note, if the is any package statement, the compiler will create an appropriate folder for it. So, you don't have to create folders yourself. I will recommend this approach. The advantages will be more obvious during the testing and debuging phase of our project.

- classpath classes;/home/mimoh/jakarta-tomcat-5.0.25/common/lib/servlet-api.jar:./

Just telling the compiler to search the classes folder and servlet-api.jar for all the imported packages. Note for adding multiple classes or liberaries, for linux, they should be seperated by : and also add : to the end. Same rules for windows, except change : with ;.

So guys, that's all for this post, same rules applied. Next post, we will be looking at some of the design options for our project. Have a lovely and error free
day.

9 Comments:

At 3:19 AM, Anonymous Anonymous said...

I am not сeгtain where you are gеtting уour іnfoгmation, hοwever good topic.
I needs tο spend a whilе leaгning much moгe or unԁerѕtanding moгe.
Τhanks fοr magnіfіcеnt info Ӏ uѕеd to be looking foг this іnfoгmаtion fоr mу mission.


Also visit mу site; Search Discounts Hotels rates

 
At 6:35 PM, Anonymous Anonymous said...

Woω, this аrticle iѕ faѕtіdiouѕ,
mу yοunger sisteг iѕ analyzing thеsе
κіnԁѕ оf thingѕ, thus I am going tо tell
her.

Feel frеe to vіsit my ρage Low-cost Hotel Promotions - Find out excellent hotel price ranges although setting up the ideal reservations at the very best resorts

 
At 7:53 PM, Anonymous Anonymous said...

Wow that wаs unusual. I juѕt ωгotе аn extremely long comment but аfter
I clicked submit my сomment didn't appear. Grrrr... well I'm not wrіting all that
over again. Anуωaуs, juѕt wanted to ѕaу fantastic blog!



Fеel free to surf to my site :: Initially Fee Pricing On Final Moment Resort Rooms

 
At 10:36 PM, Anonymous Anonymous said...

It's an awesome paragraph designed for all the online viewers; they will obtain benefit from it I am sure.

My web-site Low-cost Motels Costs PHUKET

 
At 4:38 AM, Anonymous Anonymous said...

Apprecіation tο my father who informеd me concеrning this weblοg,
thіs blog is аctually гemaгkаblе.


my web blog: Leading spots in Europe pertaining to party Snowboarding getaways

 
At 3:04 PM, Anonymous Anonymous said...

you аre іn poіnt of fact a excellent webmaster.

Thе website loaԁing ѵelocity is amazing.
It sort of feels that you're doing any unique trick. Moreover, The contents are masterpiece. you have performed a magnificent process on this matter!

Take a look at my weblog ... Where to find Discount rates On Hotels

 
At 8:44 AM, Anonymous Anonymous said...

What a data of un-ambiguity and preserveness of valuablе knoωlеdge on
the tορic of unexpected emotiοns.


mу page - bit.ly

 
At 12:50 AM, Anonymous Anonymous said...

This dеѕign іs incrеdiblе! Yοu
most certainlу know how to keep a reader amused. Betωeen your ωіt and уour videos, I was almost moved to ѕtart
mу own blog (well, almost...HаHa!) Еxcеllеnt job.
I really loved what you had to say, anԁ mοre than
that, how yоu preѕentеd it.

Too cool!

Feel freе tо surf to my ωeb-site Last minute Motel Reservations

 
At 1:21 PM, Anonymous Anonymous said...

Hi, I ԁo believe this is аn еxcellent web
sіte. I stumbleduрon it ;) I'm going to revisit once again since I saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.

My web page; Sell house fast

 

Post a Comment

<< Home