title: How to call Java API from Ruby 1.8 or 1.9
body: <p>I've this <strong>JRuby</strong> <em>working</em> code (stolen from <a href="http://kfahlgren.com/blog/2007/03/02/borrowing-javas-xslt-support-for-ruby/" rel="nofollow">Keith's Blog</a>), which wraps the SAXON xslt processor API. </p>
  
  <blockquote>
    <p><strong><em>Now, I wonder whether I can and how can I wrap the same API in Ruby framework?</em></strong></p>
  </blockquote>
  
  <p>Please tell me if this question is non-sense or if it can be improved in some way.</p>
  
  <p>This is the java doc reference for the wanted <a href="http://download.oracle.com/javase/1.4.2/docs/api/javax/xml/transform/package-summary.html" rel="nofollow">API</a>.</p>
  
  <p>And this is the JRuby code I'm using:</p>
  
  <pre><code>require 'java'
  module JXslt
    include_class "javax.xml.transform.TransformerFactory"
    include_class "javax.xml.transform.Transformer"
    include_class "javax.xml.transform.stream.StreamSource"
    include_class "javax.xml.transform.stream.StreamResult"
    include_class "java.lang.System"
  
    class XsltProcessor
      def transform(xslt,infile,outfile)
        transformer = @tf.newTransformer(StreamSource.new(xslt))
        transformer.transform(StreamSource.new(infile), StreamResult.new(outfile))
      end
    end # XsltProcessor
    class Saxon &lt; XsltProcessor
      TRANSFORMER_FACTORY_IMPL = "net.sf.saxon.TransformerFactoryImpl"
      def initialize
        System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_IMPL)
        @tf = TransformerFactory.newInstance
      end
    end
  end 
  </code></pre>