Forum: JRuby Executing initialization code before java_import in JRuby

2ff62ce4120fba75903decc672dcd88b?d=identicon&s=25 Nitish Upreti (Guest)
on 2013-07-23 19:21
(Received via mailing list)
Does java_import always execute before initialize in JRuby?

I need the following code to execute

def initialize vlc_path
    @vlc_path = vlc_path || get_vlc_path
    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName,"/Applications/VLC
.app/Contents/MacOS/lib")end

before I can use:

java_import 'uk.co.caprica.vlcj.binding.LibVlc'

The java_import always executes first and fails. How to go about it?
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-07-24 00:05
(Received via mailing list)
I guess I'm confused. Can you clarify a few things for me?

* Are you saying that even if the "def initialize" is before the
"java_import", the "java_import" runs first? They should happen in the
order they're encountered in the code.
* Why do you need to have this method defined before you import that
class?

I think I might have seen some discussion about this that indicated
you are using a precompiled .rb class, yes? In that case, imports may
be loaded earlier than the rest of the script. You could try to move
the imports to a separate script.

Can you explain more about what you're doing?

- Charlie
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-24 01:53
(Received via mailing list)
I may be missing something here, but I think the problemis that
java_import is evaluated when the class is loaded, whereas the
modification to @vlc_path is not happening until the class' instance is
created.

Is the java_import inside the initialize() method?  Also, how is the
java_import going to know anything about @vlc_path? I don't know
anything about NativeLibrary.addSearchPath(), but did you mean to use
@vlc_path in that call?

- Keith

Keith R. Bennett
http://about.me/keithrbennett
2ff62ce4120fba75903decc672dcd88b?d=identicon&s=25 Nitish Upreti (Guest)
on 2013-07-24 04:24
(Received via mailing list)
Sorry for a little ambiguity in my question. I am using JNA to access
VLC.
For

java_import 'uk.co.caprica.vlcj.binding.LibVlc'

to work, I need the VLC native files "libvlc" to be in the search path.

I would my code to look for default vlc installation search paths, if
user
does not supply one. So the code ( updated ) serves this purpose :

def initialize vlc_path=nil
      @vlc_path = vlc_path || get_default_vlc_path
      NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName,@vlc_path)
end


So I want that as soon as my class is initialized it adds the search
path
and then imports the 'uk.co.caprica.vlcj.binding.LibVlc'.
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-07-24 04:50
(Received via mailing list)
I understand that, but do you understand my question about the timing of
the evaulation? Where in your code is the import statement?

- Keith

Keith R. Bennett
http://about.me/keithrbennett
2ff62ce4120fba75903decc672dcd88b?d=identicon&s=25 Nitish Upreti (Guest)
on 2013-07-24 04:54
(Received via mailing list)
I have the java_import statement inside the class declaration and not in
my
initialization method.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-07-24 05:14
(Received via mailing list)
You could put the java_import in the initialize...or in a "singleton"
initialization method somewhere in your system you call only once. It
sounds like the it's loading in expected order based on the way you
have it laid out.

- Charlie
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.