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.

URLClassLoader
 Post subject: URLClassLoader Post rating: 0   New post Posted: Fri 31 Dec, 2010, 10:50 

User rating: 0
Joined: Fri 31 Dec, 2010, 10:11
Posts: 2
Hello.

I have a problem with a ClassLoader

Without IStrategy It work. But if I try it run, then strategy stopped.

try{
File file = new File("c:\\myclasses\\");

// Convert File to a URL
URL url = file.toURL();
URL[] urls = new URL[]{url};

// Create a new class loader with the directory
ClassLoader cl = new URLClassLoader(urls);

// Load in the class; MyClass.class should be located in
// the directory file:/c:/myclasses/test/loaded
Class cls = cl.loadClass("test.loaded.LoadedClass");

} catch (Exception e){
e.printStackTrace(context.getConsole().getErr());
}

The problem in next code:
...
Class cls = cl.loadClass("test.loaded.LoadedClass");
...


Attachments:
File comment: LoadClass.java - it is strategy and it does not work
But TestLoadClass - works

src.zip [2.19 KiB]
Downloaded 351 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: JFOREX-2581 URLClassLoader not work Post rating: 0   New post Posted: Wed 05 Jan, 2011, 17:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,

Please be sure that the compiled java class is located in the loading package. Try to put the attached zip package to the c:\temp directory, change the file variable to File file = new File("c:\\temp\\"); and try to load class with name Loaded: Class cls = cl.loadClass("test.loading.Loaded") ;.

For details please take a look at the following JForex Wiki page: https://www.dukascopy.com/wiki/index.php ... java_class


Attachments:
test.zip [921 Bytes]
Downloaded 359 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: URLClassLoader Post rating: 0   New post Posted: Sat 22 Jan, 2011, 19:09 

User rating: 0
Joined: Fri 31 Dec, 2010, 10:11
Posts: 2
Hello,
I put interface Loaded into load_test.jar and write:

...
@RequiresFullAccess
@Library("C:/Dukaforecast/lib/test_load.jar")
public class LoadClassExample implements IStrategy {
...

...
Class cls1 = cl.loadClass("test.loading.LoadingClass");
console.getOut().println("Loaded: " + cls1);
Loaded l = (Loaded) cls1.newInstance();
l.getAnswer();
...

But I have exception:
java.lang.ClassCastException: test.loading.LoadingClass cannot be cast to test.loading.Loaded


Attachments:
test_load.zip [549 Bytes]
Downloaded 351 times
LoadClassExample.java [1.84 KiB]
Downloaded 350 times
test.zip [1.27 KiB]
Downloaded 356 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: URLClassLoader Post rating: 0   New post Posted: Sun 06 Feb, 2011, 15:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
viking_zp wrote:
Class cls1 = cl.loadClass("test.loading.LoadingClass");
console.getOut().println("Loaded: " + cls1);
Loaded l = (Loaded) cls1.newInstance();
l.getAnswer();
...

But I have exception:
java.lang.ClassCastException: test.loading.LoadingClass cannot be cast to test.loading.Loaded


Please replace the line Class cls1 = cl.loadClass("test.loading.LoadingClass"); with the following line:
Class cls = cl.loadClass("test.loading.Loaded");


 

Jump to:  

cron
  © 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