JRuby Cookbook example 1.10

I can not seem to get Example 1.10 to work using Netbeans 6.51 or 6.7. I
create a Java Application project in Netbeans and pasted the code from
the
book in verbatim.

I was finally able to resolve org.jruby.Ruby by specifically adding
C:\Program Files\NetBeans 6.7\ruby2\jruby-1.2.0\lib\jruby.jar
to the library options for the project - not ideal I think but it works

But that still left me with these errors:

package org.jrubycookbook.ch01; // incorrect package name - also, is
this
perhaps where PrintJavaClass should reside?

public class PrintJavaClass // PrintJavaClass is public, it should be
declared in a file named PrintJavaClass.java

List interfaces = Arrays.asList(o.getClass().getInterfaces()); //
Incompatible types required java.util.List<java.lang.Class> found
java.util.List<java.lang.Class<?>>

What environment where you using where you didn’t get these errors?

Carl G. wrote:

Actually I did find instances of the jruby.jar but I think for some reason
these are not considered path of the default classpath

C:\Program Files\NetBeans
6.7\ruby2\jruby-1.2.0\lib\jruby.jar\org\jruby\Ruby.class
C:\Program Files\NetBeans 6.5\ruby2\jruby-1.1.6\lib\jruby.jar\org\jruby
Ruby.class

Carl G. wrote:

6.7 download (Java and Ruby) and also tried adding Ruby and JRuby plugins
to download some associated sample programs or libraries or the I need to
But I see no call to “to_java” in the sample code.
import org.jruby.javasupport.JavaEmbedUtils;
interfaces);
writer.printf(“%s (inside array), implements %s\n”, className,
+ “puts "#{o.to_s} - #{@printer.output(o)}"\n”
runtime.evalScriptlet(script);
JavaEmbedUtils.terminate(runtime);
}
}


View this message in context:
http://www.nabble.com/JRuby-Cookbook-example-1.10-tp24263046p24263046.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

On Mon, Jun 29, 2009 at 10:41 PM, cag[email protected] wrote:

I can not seem to get Example 1.10 to work using Netbeans 6.51 or 6.7. I
create a Java Application project in Netbeans and pasted the code from the
book in verbatim.

This sample worked as far as I tried although the output was bit
different shown in the book.

I was finally able to resolve org.jruby.Ruby by specifically adding
C:\Program Files\NetBeans 6.7\ruby2\jruby-1.2.0\lib\jruby.jar
to the library options for the project - not ideal I think but it works

You did in a very common way as described at
Redirect Page.

But that still left me with these errors:

package org.jrubycookbook.ch01; // incorrect package name - also, is this
perhaps where PrintJavaClass should reside?

Package hierarchies are mapped to directory(folder) hierarchies. The
example has org.jrubyvookbook.ch01 for its package name, so
PrintJavaClass.java file must reside under the org\jrubycookbook\ch01
directory. Probably,

would help you to figure out what the package is.
Since you are using NetBeans, you don’t need to create folders by
hand. Developing General Java Applications might be
good for you.

public class PrintJavaClass // PrintJavaClass is public, it should be
declared in a file named PrintJavaClass.java

Yes. Public classes should be in the same filenames, so your program
should be written in org\jrubycookbook\ch01\PrintJavaClass.java. You
can found a lot of information by googling since this is a basic part
of Java.

List interfaces = Arrays.asList(o.getClass().getInterfaces()); //
Incompatible types required java.util.List<java.lang.Class> found
java.util.List<java.lang.Class<?>>

I’m not sure why you got this error. The error might be resolved if
you could set up your Java project correctly on NetBeans.

-Yoko

C:\Program Files\NetBeans

disheartening to get bogged down this early in the book.
special directory or add an environment setting or a netbeans option so

import java.io.StringWriter;
public String output(Object o) {
PrintWriter writer = new PrintWriter(new StringWriter());

           + "output(true)\n"

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email