Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

ClassLoader Functionality
 Post subject: ClassLoader Functionality Post rating: 0   New post Posted: Tue 18 May, 2010, 16:47 

User rating: 0
Joined: Sat 07 Nov, 2009, 00:25
Posts: 11
:? Hey,

I'm desparately looking for a way to access resources that are in my jar file. More specificly, after declaring
@Library("myLibrary.jar")
I want to be able to use an audio file (e.g. audio.wav) that has been packed inside of myLibrary.jar.

I use Netbeans and within my development environment, I would use one of the following statements:
ClassLoader.getSystemResource("audio.wav");
this.getClass().getClassLoader().getResource("audio.wav");
this.getClass().getResource("/audio.wav");
of which all work fine. Within JForex however, ClassLoader only searches the current directory and the JForex/Strategies folder. It does not search the jar file loaded into the @Library annotation.

I hope it's somthing simple that I've missed but if the solution is complex, please dont hold back on detail. I am a little new to this jForex family but Java and I are well acquainted ;)



Mr A. Anderson


 
 Post subject: Re: ClassLoader Functionality Post rating: 0   New post Posted: Wed 19 May, 2010, 10:08 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello Mr A. Anderson,
Please try to use this statement:
Thread.currentThread().getContextClassLoader().getResource("resources/sample.wav");


 
 Post subject: Re: ClassLoader Functionality Post rating: 0   New post Posted: Tue 08 Jun, 2010, 16:05 

User rating: 0
Joined: Sat 07 Nov, 2009, 00:25
Posts: 11
Thanks for the reply,

Your suggestion does work but only for the initialising thread (the one that calls onStart()). It appears that the ticks all run on individual threads and so calling
Thread.currentThread().getContextClassLoader()
on another thread may at times return null.

I tried saving the working class loader to a static reference so I can use it again at any time but that attempt also proved unfruitful: the class loader is found but cannot find the resources.


Any other thoughts.
Mr A. Anderson


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com