swt icon indicating copy to clipboard operation
swt copied to clipboard

NameError: uninitialized constant Swt

Open DouglasAllen opened this issue 12 years ago • 6 comments

I'm on Windows XP 32 Using pik and jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) Client VM 1.7.0_25-b17 [Windows XP-x86]

I can run the sample button.rb which uses the swt lib from the repo. If I comment out the line $:.unshift(File.expand_path("../../lib", FILE)) and the swt gem is installed in C:\jruby-1.7.4\lib\ruby\gems\shared\gems\swt-0.16

I get that NameError: uninitialized constant Swt

Now that's from my G:\ drive with all my local repos.

If I go to C:\ where jruby is and run jruby -S jirb

require 'swt' => true Swt.constants NameError: uninitialized constant Swt

This all started when I tried to run shoes4 which depends on swt gem version 0.16

Clearly something is not right for my windows install. Can you help me?

DouglasAllen avatar Sep 12 '13 00:09 DouglasAllen

Hi Douglas, this is where the JAR loader should end up.

Could you give me the output of RbConfig::CONFIG["host_os"] and RbConfig::CONFIG["host_cpu"] from your PC?

you can just type them into IRB.

Cheers, Tobi

edit: from your JRuby installation of course :-)

PragTob avatar Sep 12 '13 09:09 PragTob

Hi Tobi,

On Windows8, x64 architecture: jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_41-b02 [Windows 8-amd64]

RbConfig::CONFIG["host_os"] is "mswin32" RbConfig::CONFIG["host_cpu"] is "x86_64

The issue is that some important SWT classes are not accessible:

For a button Widget, Swt::Widgets::Button.new(my_shell, Swt::SWT::PUSH) -> OK, NO PB.

But for a Canvas widget (same with Group),

Swt::Widgets::Canvas.new(my_shell, Swt::SWT::NONE) -> NameError: uninitialized constant Swt::Widgets::Canvas const_missing at org/jruby/RubyModule.java:2631

I checked the Vendor jars (swt-win32.jar andswt-win64.jar), path to jars are OK and clsses are in the jars with the proper name !

I spent 2 days now on this one and i need Group and Canvas. Could you please tell me if you have a solution for this ?

Thank you !

François-Xavier.

talgorn avatar Sep 18 '13 11:09 talgorn

When I initially created this gem for Redcar, I didn't import all the SWT classes, only the ones I needed: https://github.com/danlucraft/swt/blob/master/lib/swt/full.rb

I think you can get import into Ruby any other class you need like this:

module Swt
  module Widgets
    import org.eclipse.swt.widgets.Canvas
  end
end

danlucraft avatar Sep 18 '13 11:09 danlucraft

Works like a charm... :-)

Thank you very much for your quick and accurate reply !

Best,

talgorn avatar Sep 18 '13 13:09 talgorn

No problem :)

If you add loads more classes I'll merge a pull request to import them too.

danlucraft avatar Sep 18 '13 13:09 danlucraft

Okay awesome then I believe we can close this issue and I have some classes to add from the shoes side probably :-)

PragTob avatar Sep 19 '13 05:09 PragTob