title: How to call java method from jruby
body: <p>I am learing Jruby and i have following code in my eclipse</p>
  
  <pre><code>public class Test {
    public Test()
    {
        System.out.print("object created");
    }
    public static void main(String args[])
    {}
  }
  </code></pre>
  
  <p>Now i am exporting this project as <code>runnable jar</code>. since <code>runnable jar</code> looks for main method, So i have created main method.</p>
  
  <p>Now i can create object of <code>Test Class</code> in jruby like this </p>
  
  <pre><code>require 'java'
  require 'test.jar'
  
  foo = Test.new
  </code></pre>
  
  <p>and it is giving me the output <code>object created</code></p>
  
  <p>Now i want to export it as <code>jar</code> instead of <code>runnable jar</code>. So for exporting project as <code>jar</code> <code>main method</code> is not required.</p>
  
  <p>So my java code looks like this</p>
  
  <pre><code>public class Test {
    public Test()
    {
      System.out.print("object created");
    }
  }
  </code></pre>
  
  <p>Then i am again creating object of <code>Test Class</code> same as above</p>
  
  <pre><code>require 'java'
  require 'test.jar'
  
  foo = Test.new
  </code></pre>
  
  <p>Now it is giving me the error</p>
  
  <pre><code>NameError: uninitialized constant Test
    const_missing at org/jruby/RubyModule.java:3309
            &lt;top&gt; at test.rb:4
  </code></pre>
  
  <p>Since i am new to jruby, i don't know why exporting as <code>runnable jar</code> works but exporting as <code>jar</code> doesn't works.</p>
  
  <p>And which one is the best way, to export as <code>runnable jar</code> or to export as <code>jar</code>.</p>
  
  <p>Please explain in detail since i am new to jruby and there are not much documentation provided.</p>