Equivalent of the package xxx

Is there any way to “be equivalent to” the package declaration in a
.java file?

Something like this in java:

package org.familysearch.digitalarchive.tapeingestreader;

in ruby becomes something like

java_import “org.familysearch.digitalarchive.tapeingestreader.*”

Thanks.
-r

package org.familysearch.digitalarchive.tapeingestreader;

in ruby becomes something like

java_import “org.familysearch.digitalarchive.tapeingestreader.*”

Looks like it’s not possible in the global namespace (?)

but is within a module.

module M; include_package
“org.familysearch.digitalarchive.tapeingestreader”; end

Anybody know how to do this into the global namespace? Or to somehow
enumerate the java classes within a package, so you can fake it?

-r

Anybody know how to do this into the global namespace? Or to somehow
enumerate the java classes within a package, so you can fake it?

Looks like it is possible, like this:

module M
include_package “javax.swing”
include_package “java.awt”
include_package “java.awt.image” # BufferedImage
BufferedImage
end

class Object
class << self
alias :const_missing_old :const_missing
def const_missing c
M.const_get c
end
end
end

BufferedImage # works
JFrame # works

You’d think that this would work, as well:

require’java’

module M
include_package “javax.swing”
include_package “java.awt”
include_package “java.awt.image” # BufferedImage
BufferedImage
end

include M
BufferedImage # works
JFrame # this line fails

Is this a bug?

possibly related: http://jira.codehaus.org/browse/JRUBY-5107

Thanks!
-r

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs