Friday 26 November 2010

Tomcat JNDI configuration for auto redeploy

With thanks to http://www.mail-archive.com/users@tomcat.apache.org/msg74521.html

Although it's deprecated putting the context in server.xml seems to work quite nicely
however if you want to auto deploy e.g. on a CI server then you need to get a bit cleverer....

Don't keep the application in the appBase - locate it outside of
Tomcat's directory structure, and use the docBase attribute of the
element to tell Tomcat where to find it. Replace the .war file at your
leisure, and then do a touch of the .xml file to trigger an application redeployment

1) I have created a folder with absolute path:
##war directory##
2) In this folder I have placed my WAR file, ##Application##.war
3) In apache-tomcat-6.0.20/conf/Catalina/localhost
I have placed a file called ##Application.xml## (contents of file below).



<?xml version="1.0" encoding="UTF-8"?>

<Context docBase="##war directory##/##Application.war##">
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/XXXXXX"
username="YYYYYY" password="ZZZZZZ" maxActive="20"
maxIdle="10"
maxWait="-1"/>
</Context>

Wednesday 24 November 2010

Fun with classloaders

Class loaders are one of those things which work most of the time and you don't have to worry about but when they go wrong they can be a bit of a nuisance to sort out.

When you are running a java application in a application server there are several class loaders in play e.g. for tomcat see http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
Most of the time this is what you want and any other behaviour would cause problems - think Singletons - however sometimes you are trying to be clever and using a method like Class.forName or ClassLoader.getResource in which case you need a better grasp on what is happening.

In this case you can use Thread.currentThread().getContextClassLoader() or Thread.currentThread().getClass().getClassLoader() as well as Class.getClassLoader to access the different class loaders and hopefully the class/resource which you are after.

Monday 8 November 2010

Quotes I like

“If I had eight hours to chop down a tree, I'd spend six hours sharpening my ax” Abraham Lincoln

Wednesday 27 October 2010

New javascript document

A small javascript code fragment for creating a new document containing part of an existing document
var newDoc = document.implementation.createDocument("", "", null);
var sd = newDoc.importNode(content, true);
newDoc.appendChild(sd);

Monday 16 August 2010

Sorting out CAS and Drupal installation problems

How to install self signed certificates for use with the CAS single sign on system:
http://blogs.sun.com/andreas/entry/no_more_unable_to_find
(Note that you will need to use the hostname as installed)

Drupal:
Menu items not showing up when clean urls are switched on.
It's probably a problem with apache mod_rewrite.

How to switch off clean urls using the database
In the variables table change the value of clean_url to s:1:"0";
Then truncate all the cache tables

Apache2:
How to enable mode_rewrite
sudo a2enmod rewrite

How to check if mod_rewrite is enabled
Create a .htaccess file containing the following:
RewriteEngine on
RewriteRule testpage\.html http://www.google.com [R]

If going to testpage.html sends you to google then it's working

If it's not working...
[Ubuntu] check /etc/apache2/mods-enabled to make sure that there's a sym link to ../mods-available/rewrite.load
Check in sites-enabled that
AllowOverride is set to All (by default it's None)