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.


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

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

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

Friday, January 06, 2006

Developing a simple J2EE Web Project

This is my first J2EE web application project.

Project Description :
It is a simple project, let's call it Personnel Management System.
It is a 3-tier application. A user should be able to log on to the site,
base on the user name and password, which will stored in a database, the user is authenticated and authorised.

Development: Servlet, Jsp and EL.
Database: Mysql
Web Container: Tomcat

Linux 9.0 (for windows user, this is java)
WORA (Write once Run Anywhere)
Other decisions and requirements will be made during the
development and deployement process.

Welcome to Java/ Linux Den

Hi guys,

welcome to my den. Here, i intend to share resources with Java/J2EE Developers and other interested parties. This is just the begining of a whole lot of new experience. Don't go away,just sit tight and fasten your belt as we take on this journey to liberate our mind from the closed world of programming.

I intend to make my first series of post by the weekend. The example codes are going to be tested and so explained that my grandma, who is over 100 yrs will understand. Please fill free to mail me your questions,observation and criticism.
Thanks for visiting, please your cup of coffee will be delivered to you in the next 5 mins.