Monday, July 31, 2006

JoyTip101

Looking for a simple alternative to JDBC? Check out iBatis Data Mapper! It may not be as full featured as existing ORM tools such as Hibernate or EJB, but why the need to go complex when we can be simple? Maybe all we want is to simply get rid of that chunky JDBC code, and simply have queried data mapped directly to java beans.

Play around with it. It'll be a blast.

Tuesday, June 27, 2006

Joytorial Lession #1: Easiest Way to Run Your First Struts Application

Struts framework is a widely used framework for java web development. It has been around for quite a while and has evolved into a powerful development framework.

It's just been a year since I learned Struts. During that time, I was using Struts In Action as a guide to learn Struts. It did help a lot in terms of learning what the concept is behind the Struts framework, but it didn't teach you how to actually set it up from scratch. I tried looking for other tutorials online but what I did get are usually sample projects that have already been prepared for the user. And so I decided to create this simple tutorial for one to setup and run the simplest struts application.

This is the simplest and easiest way that I could think of. I won't be discussing much detail as to the concept behind struts. I would just be providing a startup point for learning and understanding the framework. I firmly believe that once you get this thing going, that's when you actually understand what ActionForwarding is really about, or what tiles actually do (experience + read documentation = understanding). Get into the action and you'll learn faster!

Anyway, you would be needing:
struts-blank.war <-- usually bundled together with the struts release (google it or download struts release from its website: Struts Apache)
eclipse IDE <-- IDE that we will be using
Tomcat <-- 4 or 5 would do.

Steps:

1.0 Prepare our project

1.1 Unpack struts-blank.war: the topmost folder is named struts-blank, and contents of the folder would include the usual WEB-INF, src, etc. Place this folder under the directory which you would like it to appear.

1.2 rename folder to a project name of your choice. I named mine.... Joytorial-Struts101

01_rename_folder
Note: you can actually not rename the file and simply use struts-blank folder name

1.3 Here's the contents of our Joytorial-Struts101 Folder

02_before_eclipse_project

2.0 Open our Project in Eclipse

Now we're ready to open the project into our IDE. I am using Eclipse 3.1.2.

2.1
Click on FILE -> NEW -> PROJECT from menu.

2.2 From the popup screen, please choose Java Project and press NEXT button.

2.3 We would like to create a new project based from existing source (since we've already prepared our struts project). Below are the details of my project.

03_new-java_project

2.4 After setting up the project as seen above, clicking NEXT would allow me to modify my project build files, sources, etc. And clicking FINISH will allow me to go back to the main workspace and skip the other requirements of creating a new java project process. (I'd personally prefer modifying my project properties after I've opened the project itself in the workspace).

So here is what my navigator list would look like after I click on FINISH:

04_navigator_list

2.5 Now we shall modify our project properties. To do so, please pick your joytorial-Struts101 project folder, right click, and choose properties, after which, click on Java Build Path.

There are two crucial actions we have to perform during this process:

2.5.1 Modify our output folder (as seen by the red marks from the figure below).

05_default_output_folder

Note: We would want out compiled classes to go straight to our WEB-INF/classes folders as this is a web application we are creating.

2.5.2 We need a servlet library (servlet-api.jar)! But where to we get it? We get it from our installed Tomcat Server. In my case, I've installed my tomcat 5 in C: and following its default directory system, I will find my servlet-api.jar on the following directory:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib
Note: It is not advisable that you copy the servlet-api.jar from your tomcat to your WEB-INF/lib directory because your project will now depend on the container version. If this is the case, everytime you change container version (Tomcat 4.0 to Tomcat 5.0 for example), then you'd have incompatability issues because the servlet-api.jar in your WEB-INF/lib is not of the same version as the servlet container you are using.

Now, let us add the servlet-api.jar to our java build paths.
HOW? Here's a simple step by step instruction.
1. Go back to Project properties
2. Java Build Path
3. Click tab for Libraries
4. Click on button Add External Jars
5. Look for servlet-api.jar (either from the tomcat common/lib) and press open button
6. Press OK
7. We're Done!
3.0 Setup Tomcat

Now it's time to setup our conf file. In order for tomcat to know that your project is ready to run, you have to tell tomcat that it can access this project from its directory. How? By creating a simple xml file.

Creating these xml files may be complicated. But for us beginners, we'll use the simplest possible way to create such a file. It's up to you to further add more details to it. For now, our main goal is to simply get our first struts application up and running.

Go to: (or wherever your tomcat is located)
C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost

Get what's inside Manager.xml, copy and paste it in a notepad, and save as "joytorial-Struts101.xml" (or whatever name you want as long as it's saved as an xml file.

06_managerxml

Of course we have to modify what's inside as we've simply copied it off from Manager.xml!

07_joytorialxml

In this context file, there are 2 definitions that we need to modify and take note of:
docBase - actual directory of your struts project
path - this is the pathname that you will be using to run your program in the browser (e.g. http://localhost:8080/path)

Note: In advance topics, this context file can still be modified in so many ways.

4.0 Run Run Run!

Run your tomcat server.

Go to any browser you use (IE, Opera, Mozilla, etc) and type in: http://localhost:8080/joytorial-Struts101

The actual format of this address is actually: http://localhost:port/pathname
where port is usually 8080 or 8888 (depends on your tomcat server, or what is defined there), and path is the path name of the project you defined in the .xml file.

If you find this in your web browser:

08_welcomeStruts

There you have it! You now have a working struts application!

Practice project #1 Update

After coming home yesterday at around 5:15 pm (Early dismissal for us! woohooo), I was feeling dizzy and all so I took a nap. Unfortunately, I woke up and later that night, I couldn't go back to sleep so I decided to update my mini practice project.

So far, I was able to run my application with struts and iBatis. I tried using JAAS then, but since I've reformatted my computer, I also threw away a lot of app projects, so in order to relearn JAAS, I shall implement this to my current practice project as well.

I've also installed MySQl Query Browser. I tried installing Toad for MYSql but I couldn't make it to work (I believe this is because of the .NET applications that I've installed a couple of weeks back).

That's it for now.
My brother's pushing me to setup the subversion with httpd access already.

Monday, June 26, 2006

Current project #1

Currently, aside from work, I've been doing some research and development stuff at home. I've been developing a small payroll system (for my dad), for free, and doing it as a testbed as well.

I've used Struts and iBatis at work, but it's a totally different world when you're actually doing the project from scratch, because at work, it's all been setup for you (by the seniors). So, this is the reason why I want to start a project from scratch, and use something I'm familiar with already. But it's still not that easy. I'm now learning how to create ant build files! But it's all cool.

So I now have:
Struts
IBatis

My progress has been slow since when i come home from work I'm usually tired as hell already and would prefer to just lie down and watch TV.

Programs I use for development

Since I have a day job as a programmer, I've also decided to prep up our personal computers at home (2) to stand as research and development workstations.

For my computer, which runs at P4 1.5 gigaHertz, with 80 and 20 gig harddrives and 512 DDRAM, I've installed and setup the following programs:

  1. Eclipse 3.1.2 (as my java Development IDE)
  2. MySQL (testbed database)
  3. Fabforce's DB Designer (to design my database and automatically sync to mySQL server)
  4. Apache Tomcat 5 (Container)
  5. Apache Httpd Server (tried using this to create my own web repository to be accessed elsewhere)
  6. Subversion as repository for the two computers (Subversion is installed on my brother's PC, which I shall be learning to fully configure and setup hopefully within the week)
  7. J2SDK (Of course!! who'd leave this out?)

Welcome.

I am apparently a geek.

I am still at this process of wanting to know more and more abuot different technologies there are available out there with regards to development, programming, etc. I've tried incorporating techie stuff to my other journal, which is more of a diary of my daily routine, but it just didn't mix so I decided to create a seperate one just for some of my geeky ideas.