문제

이 문서는 Java 클래스를 Jruby로 가져 오려면 JAR 파일에 있어야한다고 제안하는 것 같습니다.

"Jruby의 JAR 파일 내에서 리소스를 사용하려면 JAR 파일이 클래스 경로에 있거나 요구 메소드를 사용하여 사용할 수 있도록해야합니다."http://wiki.jruby.org/wiki/calling_java_from_jruby#require_a_jar_file_to_to_to_resources_in_the_jar_discoverable_within_jruby)

.class 파일을 직접 가져올 수 있습니까?

감사!

도움이 되었습니까?

해결책

I've managed to answer my own question :)

If your class files are compiled to a relative path of "target", e.g. foo.Bar is located in "target/foo/Bar.class", then you do the following:

require 'java'
require 'target/foo/Bar'

module Foo
  include_package 'foo'
end

puts Foo::Bar.new

And the result:

foo.Bar@1582a7c

다른 팁

I think you could also:

require 'java'
$CLASSPATH << "target"

and then

foo.bar.baz.Class.new() # ... 
# or 
java_import 'foo.bar.baz.Class'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top