23 September 2010

How to fix Tomcat5 XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom

Saw this exception on a RHEL5 box - our application stopped working after a yum update.

To fix it I deleted the symlink to /usr/share/java/xml-commons-apis.jar in /var/lib/tomcat5/common/endorsed and restarted tomcat.

The stack trace looked something like:

- XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
at javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
at com.sun.tools.xjc.reader.internalizer.Internalizer.(Internalizer.java:81)
at com.sun.tools.xjc.reader.internalizer.DOMForest.transform(DOMForest.java:448)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:221)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:52)

18 August 2010

How to Stop Debian Ignoring /etc/security/limits.conf

I was trying to increase the number of open files allowed for a user on a Debian 5 box. Changing /etc/security/limits.conf was being ignored until I added the following line to /etc/pam.d/common-session.

session required pam_limits.so

Logging out and in again after adding that line gave the new session the ulimit I was trying to configure.

Took quite a lot of googling to find this: http://www.zimbra.com/forums/administrators/16066-solved-too-many-open-files-error.html

12 July 2010

Faker for Clojure 1.1

I wanted to use Sebastián Galkin's Faker library to create some sample data. It requires some bleeding edge stuff from Clojure 1.2. but my current project is built against Clojure 1.1, so I back-ported it to work with 1.1.

You can find the code at http://github.com/doooks/faker

27 April 2010

How to Fix Tomcat5 on RHEL5 org.apache.xalan.processor.TransformerFactoryImpl not found

I got this exception trying to start a Grails app on a RHEL5 box using OpenJDK and Tomcat5, all installed from Yum.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'annotationHandlerAdapter': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]: Constructor threw exception; nested exception is javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found at java.lang.Thread.run(Thread.java:636)

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class
[org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]: Constructor threw exception; nested exception is javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found

To fix I did a yum install of xerces and xalan, created a symlink from $catalina_home/common/endorsed/xalan.jar to /usr/share/java/xalan-j2.jar and restarted Tomcat.

15 March 2010

Project Euler Problem 14 in Clojure

This one was fun. I also learned a good lesson the hard way about lazy sequences. When I was playing with the code in the REPL everything worked fine, but I got confused when I hooked everything up and started getting empty lists out of functions. It looked like functions were returning the values pointed to by the atoms before I modified them. I'd read about how lazy sequences don't get evaluated until they are required, but it didn't occur to me that "for" would return immediately, without evaluating anything. In the REPL this doesn't happen of course.

Was also my first look at maps, and the loop macro.

Solves in about 40sec

(defn- next-int [n]
  (if (even? n)
    (/ n 2)
    (+ (* n 3) 1)))

(defn- grow [start-num]
  (let [sequence (atom (list start-num))]
    (loop [head (first @sequence)]
      (let [next (next-int head)]
        (swap! sequence conj next)
        (if (= 1 next)
          @sequence
          (recur next))))))

(defn- measure-sequences []
  (let [counts (atom {})]
    (doall
      (for [start-num (range 1 1000000)]
        (let [sequence (grow start-num)]
          (swap! counts assoc start-num (count sequence)))))
    @counts))

(defn max-map-entry [map]
  (first (sort (comparator #(> (val %1) (val %2))) (seq map))))

(defn solve []
  (first (max-map-entry (measure-sequences))))

Project Euler Problem 13 in Clojure

Really not very interesting

;; defining big list of numbers elided

(defn solve[]
(.substring (str (apply + numbers)) 0 10))

Project Euler Problem 9 in Clojure

Solves in about 16sec. I quite liked the solution though of course the forum posts on the Project Euler site show some much cleverer solutions.

(defn pythagorean-triplet? [a b c]
  (and
    (< a b)
    (< b c)
    (= (+ (* a a) (* b b)) (* c c))))

(defn solve []
  (first
    (for [a (range 1 1000) b (range a 1000) c (range b 1000)
      :when (and
        (pythagorean-triplet? a b c)
        (= 1000 (+ a b c)))]
    (* a b c))))