Tech

Technical learning posts.

Found the solution for Tomcat Start up Issue.

At last, I cracked it!

Here is the story:

Sometime back when I deploy my web application( named: myApp) in Tomcat 5.5.23 installed on JDK 1.5 Update 14, I used to stuck with the following issue and I was not able to access my application.

Tomcat log will show something like below:

INFO: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myApp\WEB-INF\lib\servlet-api.jar) – jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

28/05/2006 21:03:39 org.apache.catalina.loader.WebappClassLoader validateJarFile

INFO: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myApp\WEB-INF\lib\servlet.jar) – jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

SEVERE: Error listenerStart
Dec 5, 2007 10:24:10 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/myApp] startup failed due to previous errors.

Today I found the solution for this issue.

Just delete the servlet.jar and servlet-api.jar files from C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myApp\WEB-INF\lib.

These files, anyways will be in C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib folder of Tomcat.

I found this solution by little bit of Googling. Earlier also I Googled for this like anything but could not find any solution.I also posted it in popular forums at javaranch.com, thescripts.com, p2pwrox.com etc. but to my disappointment.

I also tested this solution in three of my team’s systems.It worked for two systems and it didn’t work for one system. But I am sure the above is the cause and fix of this issue.The reason for not working in one system is something else which I have to investigate further.

This issue consumed lot of my time/energy/hope and frustrated and depressed me a lot.I didn’t get help from anyone. Now I am glad that I found the solution all by myself.

weird naming convention of substring() method of java.lang.String class

The substring() method of java.lang.class is not inline with the Java naming conventions for methods.

As per Java naming conventions, all the methods will be in camelCase.But this does not bother substring() method.

To get sub string of any string in Java, we should use substring() NOT subString().

PS: I remember there are some other capitalization styles other than camelCase and PascalCase but could not recollect them at this moment.

The following Error related to JBoss Drools frustrated me because of Java Version mismatch.

The version of Drools we are using runs properly only with JDK 1.5 where as we are trying hard to make it run on JDK1.6 and ended up with the following issue.


java.lang.ClassNotFoundException: [Lorg.drools.rule.Declaration;

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa

der.java:1359)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa

der.java:1205)

at org.drools.rule.PackageCompilationData$PackageClassLoader.loadClass(U

nknown Source)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at org.drools.common.ObjectInputStreamWithLoader.resolveClass(Unknown So

urce)

at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:157

5)

at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)

at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1624)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323)

at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19

45)

at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

753)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at java.util.HashMap.readObject(HashMap.java:1029)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.

java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces

sorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974

)

at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

753)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at org.drools.rule.PackageCompilationData.readExternal(Unknown Source)

at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:179

2)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

751)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at org.drools.rule.Package.readExternal(Unknown Source)

at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:179

2)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

751)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at java.util.HashMap.readObject(HashMap.java:1029)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.

java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces

sorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974

)

at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1846)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

753)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at org.drools.common.AbstractRuleBase.doReadExternal(Unknown Source)

at org.drools.reteoo.ReteooRuleBase.readExternal(Unknown Source)

at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:179

2)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1

751)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

at com.infosys.ipsp.ade.impl.RuleBaseRepositoryImpl.deSerializeRuleBase(

RuleBaseRepositoryImpl.java:73)

at com.infosys.ipsp.ade.impl.RuleBaseRepositoryImpl.deSerializeRuleBase(

RuleBaseRepositoryImpl.java:85)

at com.infosys.ipsp.ade.userinteraction.ConsultationServlet.doGet(Consul

tationServlet.java:108)

at com.infosys.ipsp.ade.userinteraction.ConsultationServlet.doPost(Consu

ltationServlet.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:269)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:188)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV

alve.java:210)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV

alve.java:174)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j

ava:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j

ava:117)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal

ve.java:108)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav

a:151)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java

:870)

at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p

rocessConnection(Http11BaseProtocol.java:665)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo

int.java:528)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol

lowerWorkerThread.java:81)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP

ool.java:685)

at java.lang.Thread.run(Thread.java:619)

MS SQL Server 2K and Win XP

MS SQL Server 2000 Enterprise Edition Server componentscan not be installed on Windows XP.

Only client components can be installed.

I am exploring how to install Personal Edition on Win XP.I thought I will post it after I successfully do it.But we again did not use it and got the work done with Enterprise Edition.So this is the end of Personal Edition.

At last, we successfully deployed ASP web application.Some interesting findings:

[1] Our application can be installed on MS SQL Server 2000 Enterprise Edition ( I did) or Developer Edition (I did) or Personal Edition(I saw Gaurav Deshmukh did).

[2] Deploying ASP Web Application in IIS is easy.

[3] The whole issue started because we were trying very hard to make the user we created own our tables instead of letting those tables owned by standard “dbo” user of SQL Server.And we tried to connect with the same user we created instead of connecting to SQL Query Analyzer tool with standard “sa” user of SQL Server.

so the guy who helped us did these:

[1] Run the table creation script by standard “sa” user.
[2] So that, all the created tables will be owned by “dbo” user.
[3] Now we can create any custom user of our choice and all that we have to do is just associate this custom user with the above created database. Then we can use this custom userid and password in our configuration files(in our case it is qdo.asp) to connect to the database.

This is my first encounter with Microsoft technologies like IIS, SQL Server 2000 and ASP.

Java’s Checked and Unchecked Exceptions- demystified

Until recently, I had hard time remembering what is the difference between checked and unchecked exceptions.

Finally Head First Java gave me the prompt explanation. Here it goes:

Checked Exceptions: Arise due to the reasons which are beyond control of programmer so complier mandates them to handle or declare.

Unchecked Exceptions: Arises due to logic flaws in the code.So these should be eliminated.Exception Handling mechanism is not supposed to take care of programmer injected logic flaws in the code.So complier wont bother.It is the responsibility of the programmer to eliminate them.

I am also looking for similar kind of prompt and clear explanation for the difference between Error and Exception.If you get to know, I appreciate if you can share with me.

JScrollPane for JTextBox

I was creating a GUI using Java Swings.

I decided to add a text box with vertical scroll bar to it. I also have few more other components to be added and my text box with scroll bar comes after some of them.

So I started adding one by one,

panel.add(dateLabel);
panel.add(dateTextbox);
…..

//now the turn of description text box

panel.add(descriptionTextbox);
panel.add(scrollbarForDescriptionTextbox);
……

I compiled and ran the program. The output was weird.The descriptionTextbox is coming without scrollbar and as I continue hitting ENTER in it, it is expanding and exceeding even the frame size.And my poor scrollbarForDescriptionTextbox is lying idly next to the descriptionTextbox .

I was surprised why it is happening like this and kept looking at the code over and over again. I spent sometime even yesterday night before going to bed.But I couldn’t get it.

Today morning at 5:30 I just opened my laptop to see it again. I found the mistake I did in less than 2 minutes.

Here is the catch:

Initially I said ,

JScrollPane scrollbarForDescriptionTextbox = new JScrollPane(descriptionTextbox);

now that I created scroll bar for descriptionTextbox,I should only say

panel.add(scrollbarForDescriptionTextbox);

instead, I said

panel.add(descriptionTextbox);
panel.add(scrollbarForDescriptionTextbox);

which is a blooper! Though its OK for compiler, I didn’t get my expected output.

Tricky RESET

In HTML, reset is used to well reset the form.This means the form will be reverted to the way it was as soon as it got loaded. Here are 2 important cases.

[1] You loaded an empty form which has some fields like text boxes, check boxes, combos etc.
So when you hit on reset, as per the above definition of reset, all these fields will be reverted to the way they were as soon as the form got loaded. That means, all the fields get blank values.

[2] Assume your form has two text boxes, and two combos which I call textbox1, textbox2, combo1 and combo2 in the same order.Now the form is coded such that the values to be loaded in combo2 depends on the value selected in combo1.Very prevalent in many web applications.

Now you started filling the form, entered some text in textbox1 and textbox2, selected some value in combo1 and combo2 got loaded accordingly.Now you changed your mind and hit on reset button to reset the form but you see that the form didn’t get reset and the old values are still there in the fields. why?

The trick is this: read the definition of reset again. It will revert the form to the way it was as soon as it got loaded.Hope now you understood why it happened like that.If not, please read on.

As soon as you select some value in combo1, the form gets submitted to get the values in combo2.That means , the form is loaded again. So by the time you hit the reset button, the loaded form is not the one which has blank values for all it’s fields but the one with some text in in textbox1, textbox2 and combo1.And reset button has reset the form to that state.So what is the workaround?

Just don’t use the HTML provided reset button. Instead code your own reset button which sets the fields to blank values.

Code may look some thing like below:

DONT use

<input type=”reset” >

Instead use

<input type=”button” onclick=”ResetForm()”>

Code for ResetForm() may look something like this:

<script type=”text/javascript”></script>
function ResetForm()
{
document.yourForm.name.value = “”;
document.yourForm.description.value = “”;
document.yourForm.projectId.selectedIndex =0;
document.yourForm.projectId.disabled =true;
document.yourForm.comments.value = “”;
document.yourForm.name.focus();
}
</script>

Starting a new blog to share my Technology learnings.

Starting this blog today to pen down all my tech learnings.

I am going to use this blog to document my learnings, findings, resources etc about the technologies I come across in my day to day life.

So here I am, seeking your best wishes in this journey through Technology hinterland.

-ChaitanyaSave as Draft