NMO
NMO

Reputation: 776

"Cannot load Java class" in JRuby

I want to integrate a very simple Java file into my JRuby app. Unfortunately, it doesn't work.

Simple.java:

package com.mypackage;

public class Simple {
  public void foo() {
    System.out.println("foo called");
  }
}

I compile it with "javac Simple.java" Then I create a jar file with "jar cf mylib.jar Simple.class"

test.rb:

require 'java'
require "mylib.jar"
java_import 'com.mypackage.Simple'

When I run it with "ruby test.rb" I get the following error:

NameError: cannot load Java class com.mypackage.Simple
     for_name at org/jruby/javasupport/JavaClass.java:1286
     get_proxy_class at org/jruby/javasupport/JavaUtilities.java:34

I have no idea what I'm doing wrong. My JRuby version is: jruby 1.7.16.1 (1.9.3p392)

Upvotes: 2

Views: 1951

Answers (1)

NMO
NMO

Reputation: 776

The answer is simple. I have forgotten to put the Simple class into the folder structure com/mypackage/Simple. Java was therefore not able to find the class.

Upvotes: 1

Related Questions