Friday, February 11, 2005

Thanks for the inputs !!! ;)

Here are some more of them apart from comments (from a colleague):

"..you can place these class files in a jar directly under the application directory and once everything is done you can proceed with moving that file to lib"

-- Ya here jerry would not disturb user's directory structure! It is just the jar and lib after all!!

"..don't forget to create the lib directory in the application, if one doesn't exist. If it exist you should proceed with putting the generated jar file in that directory. Bit of logic in build.xml"

--hmm... ok

Also :

* Jerry would not bother about the compilation errors!! that is left to the user!
(Let him write the correct syntax!!)

Now jerry makes use of Logger (Atlast it is put to use for a valid reason!!) to log the compilation errors, if any.

But it is taking lot of time to start. :(

Something has to be done...

I have some more stratergies for Jerry to compile:

B4 running ANT:

* Check for the class files' modified date. If it is not less than a "considerable" time (a day or two?), do not recompile the whole app.
Just ask Jerry to run !!

* If any of the files have been changed (mainly *.java) then compile only that file or at the
worst cases compile the dependent file. Even worst case compile that app !! ;)
But not all apps in webapps!

I hope this will save some time for jerry to start!

Other important points:

* build.xml is built dynamically and saved to the disk where ant is run.

* using java.lang.Runtime.exec("ant") to execute ant.

This week-end is going to be exciting !!

WOW !!

Will blog after some improvements !!

Monday, February 07, 2005

As planned, yesterday Jerry compiled the classes in webapps folder.

Great !!

But with this i landed into a great confusion !!!

Reason :

1) How to place the class files in the app folders ?? shall i create a classes folder or just
place it where the .java is ?? Right now doing the latter. (is there any other way?)

2) I think iam playing with the users folders (some intrusion kinda thing ??!!).

3) i have a check :
if the user has his build.xml for ant
then execute that but without his permission or the intension?? (i dont know)


Boys , help me out !!

Comment on this issue as much as possible and let me know what to do. If you have any other
ideas(innovative ?!! as the compilation of classes is itself is innovative!!)

Thanks for the support!!

Tuesday, February 01, 2005

Well.., sacrificing movies on last Saturday and Sunday, managed to parse web.xml and load the mapped classes. ;)

Tomcat uses some six to seven conditions to check
whether a class requested can be loaded or not.

First , it checks in the repository before checking the mappings in web.xml. Then in the Cache.

Still some more conditions apply ...

If it does not find anywhere then it throws a
ClassNotFoundException

That is why the class could be loaded (sometimes!!) even when u have deleted the class. It could be found in cache. But once you restart the server, it'll throw the exception.

But aim (as i have been telling this for long time!!) being just to understand How Tomcat Works , i came up with only two conditions. ;)

One being the repository search or just the folder in which class is present and is well-known like /WEB-INF/classes/*.

And other being mapped in web.xml.

This is because you can have a simple Servlet in classes directory (without packages!!) which is looked after by the first condition and also you can have a servlet mapped as a controller (or anything for that matter) like:

servlet-mapping servletName = "com.mycontroller.classes.MyMainServletController" uriPattern="/servlet/MyController"

If both these conditions fail, then throw the exception.

Tomcat uses neither DOM nor SAX for parsing of the web.xml file. It uses Apache Software Foundations' (ASF) Digester project.

Look for digester here:
http://jakarta.apache.org/commons/digester/

It basically maps XML to Java objects and allows certain rules to be set.

Learnt Digester (the simple reason is i didnt know either of DOM or SAX ) ;)

You might figure out that the mappings in Struts-config.xml or web.xml like
or the or the tags are all
Classes !!

Digester parses the xml file and allows you to trigger a method on finding a certain pattern.

Example:

On finding the pattern
, you can invoke a method after assigning it to a class

digester.addSetProperties("employee","Employee");
digester.addCallMethod("employee","printName");

This will call the method printName() of the class Employee on finding pattern "employee".

Very usefull indeed !! (like all the jakarta projects) ;)

But exploration of powers of Digester was limited, should utilize it to the maximum extent (but when ??!!).

Next thing to learn is Ant (Another Neat Tool). May be i should try to compile classes when the server is restarted or when the class is modified.

Surprisingly this was my original aim !!! Ya to compile and reload the classes.

We'll see what'll happen !!

Thanks for support again!

Sunday, January 09, 2005

Did not get much time to implement and obviously to blog !!

But late in night thought of implementing only a Logger.

Logger is a program which will log (or blog !!) or writes to a file configured.

Extending to this feature, just added a ResourceBundle from which it will obtain the key String and just write it to a file.

Usage of ResourceBundle helps in i18n, for you can configure more than one bundle using different
languages.

ResourceBundle has a key/value pair Strings written in a
file , something like ApplicationResources.properties.
(Struts users will be more familiar with this name !). It contains the strings like:

key.username.invalid=Invalid User Name
....

For logging, a most common method viz., log(String stringToBeLogged) is used.

Logger makes use of Key for stringToBeLogged and gets the Value and writes it to a file.

Still have plans to implement following:

1) Digester , for parsing of XML and using it as a configuration file like that of web.xml

2) Context for getting the servlet context..

3) Loader to load all the classes configured in web.xml

and much more... somthing like JSP compiler or
JSP Engine.