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 DbConnet.java
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