Executing initialization code before java_import in JRuby

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing initialization code before java_import in JRuby

Myth17

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?


Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

Charles Oliver Nutter-4
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

On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti <[hidden email]> wrote:

> 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?
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

keithrbennett
I may be missing something here, but I think the problem is 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

On 7/23/2013 6:03 PM, Charles Oliver Nutter wrote:
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

On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti [hidden email] wrote:
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?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

Myth17
Sorry for a little ambiguity in my question. I am using JNA to access VLC. Fo

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'.
 


On Wed, Jul 24, 2013 at 5:22 AM, Keith Bennett <[hidden email]> wrote:
I may be missing something here, but I think the problem is 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

On 7/23/2013 6:03 PM, Charles Oliver Nutter wrote:
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

On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti [hidden email] wrote:
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?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

keithrbennett
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

On 7/23/2013 10:23 PM, Nitish Upreti wrote:
Sorry for a little ambiguity in my question. I am using JNA to access VLC. Fo

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'.
 


On Wed, Jul 24, 2013 at 5:22 AM, Keith Bennett <[hidden email]> wrote:
I may be missing something here, but I think the problem is 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

On 7/23/2013 6:03 PM, Charles Oliver Nutter wrote:
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

On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti [hidden email] wrote:
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?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

Myth17
I have the java_import statement inside the class declaration and not in my initialization method.  


On Wed, Jul 24, 2013 at 8:17 AM, Keith Bennett <[hidden email]> wrote:
I understand that, but do you understand my question about the timing of the evaulation?  Where in your code is the import statement?

- Keith

On 7/23/2013 10:23 PM, Nitish Upreti wrote:
Sorry for a little ambiguity in my question. I am using JNA to access VLC. Fo

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'.
 


On Wed, Jul 24, 2013 at 5:22 AM, Keith Bennett <[hidden email]> wrote:
I may be missing something here, but I think the problem is 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

On 7/23/2013 6:03 PM, Charles Oliver Nutter wrote:
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

On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti [hidden email] wrote:
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?


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






Reply | Threaded
Open this post in threaded view
|

Re: Executing initialization code before java_import in JRuby

Charles Oliver Nutter-4
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

On Tue, Jul 23, 2013 at 9:53 PM, Nitish Upreti <[hidden email]> wrote:

> I have the java_import statement inside the class declaration and not in my
> initialization method.
>
>
> On Wed, Jul 24, 2013 at 8:17 AM, Keith Bennett <[hidden email]>
> wrote:
>>
>> 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
>>
>> On 7/23/2013 10:23 PM, Nitish Upreti wrote:
>>
>> 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'.
>>
>>
>>
>> On Wed, Jul 24, 2013 at 5:22 AM, Keith Bennett <[hidden email]>
>> wrote:
>>>
>>> I may be missing something here, but I think the problem is 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
>>>
>>> On 7/23/2013 6:03 PM, Charles Oliver Nutter wrote:
>>>
>>> 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
>>>
>>> On Tue, Jul 23, 2013 at 12:16 PM, Nitish Upreti <[hidden email]>
>>> wrote:
>>>
>>> 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?
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>     http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email