2

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)

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.