Tuesday, September 15, 2009

How to configure context path (web app url) in tomcat 5

Sometimes we want to change the context path

from http://localhost:8080/mywebapp
to http://localhost:8080/somedir/otherdir/newcontext

Just follow the steps:

1) create folder configwebapp, under Catalina_home/webapps

2) copy war to Tomcat_home/webapps/configwebapp/mywebapp

3) make following entry into Tomcat_home/conf/server.xml (just above – closing of Host)

……
……

< Context path="/somedir/otherdir/newcontext"
docBase="C:/apache-tomcat-5.5.23/webapps/configwebapp/mywebapp"
reloadable="true" >
< /Context>



Restart tomcat !

----------------------------------------------------------------------------------

Friday, August 21, 2009

convert Calendar to XMLGregorianCalendar and vice-versa

Steps (method) to convert Calender to XMLGregorianCalendar:

There may be several ways to do the conversion as many methods are available in Calendar and other classes. Here is one of it:

- This may be required while working with jax-ws or jaxb.
- jax-ws uses jaxb internally.

public static Calendar fromXMLGregorianCalendar(XMLGregorianCalendar xc)
throws DatatypeConfigurationException {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(xc.toGregorianCalendar().getTimeInMillis());
return c;
}

public static XMLGregorianCalendar toXMLGregorianCalendar(Calendar c)
throws DatatypeConfigurationException {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(c.getTimeInMillis());
XMLGregorianCalendar xc = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
return xc;
}


Notes:

XMLGregorianCalendar can be instantiated with:

XMLGregorianCalendar xc = DatatypeFactory.newInstance().newXMLGregorianCalendar();

xc would be initialized with date: Thu Jan 01 00:00:00 GMT+05:30 1970

Note: If you directly try to print xc with: sysout(xc) then u will get Exception.

So you can use:
System.out.println(xc.toGregorianCalendar().getTime());
Output: Thu Jan 01 00:00:00 GMT+05:30 1970

I hope this would be useful.

Regards,
Ravindra Pandya