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.

Problem including library into JForex strategy
 Post subject: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 00:43 

User rating: 2
Joined: Thu 07 Nov, 2013, 12:15
Posts: 121
Hi folks

I'm trying to build a utility library to include into JForex strategies.

I have the apache.commons example from the Wiki working as expected:

https://www.dukascopy.com/wiki/en/development/strategy-api/practices/include-libraries.

But I can't include my own lib.

I've compiled a jar containing a single test class, with the package com.uviva.

The jar is named uviva.jar and is placed in the IContext.getFilesDir() directory.

In the strategy file I have:

import com.uviva.*;

@Library("uviva.jar")
public class MyStrategy implements IStrategy, IFeedListener {
     .....
}


The import line is showing the error: "The import ... cannot be resolved".

I've also tried:

import com.uviva;
import uviva;
import com.uviva.MyTestClass;
import uviva.MyTestClass;

Seems that I'm misunderstanding something basic. Any suggestions would be very welcome!


 
 Post subject: Re: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 08:36 
User avatar

User rating: 2
Joined: Tue 11 Jul, 2017, 09:30
Posts: 24
Location: HungaryHungary
You can try with the @RequiresFullAccess and full path:
example:

@RequiresFullAccess
@Library("E:\\JavaProjects\\ . . . \\MyCool.jar;)

avoid spaces


 
 Post subject: Re: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 12:55 

User rating: 2
Joined: Thu 07 Nov, 2013, 12:15
Posts: 121
Thanks for the suggestion but it didn't work.

It's finding the file OK - the error lights up in the editor when I put in the correct path, but not if I put in the wrong path.

So it's something about the jar file it doesn't like.

I created the jar the usual way using the standard Oracle compiler. And there's nothing exotic in it - just a simple class.

So what can it be about the jar file that's causing JForex to barf? I'm at a bit of a loss...


 
 Post subject: Re: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 16:02 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See the attached strategy and jar.
Please note that @Library path must be updated accordingly


Attachments:
example.zip [1.19 KiB]
Downloaded 85 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: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 17:35 

User rating: 2
Joined: Thu 07 Nov, 2013, 12:15
Posts: 121
Hi

Thanks for getting back so quickly! But I'm still stuck :( .

As I say, the starting point is that I have the code in the Wiki example working properly with the commons-lang3 jar file out of the .../Strategies/file directory. So its not a basic file permissions issue or anything like that.

When I try your example com.dukascopy.App jar in my Documents directory (adding @RequiresFullAccess) it finds the file OK but gives the error "Unable to load target class" on compile. Same result if the jar is in the .../Strategies/file directory.

As I said above, with my own jar in the .../Strategies/files directory, I get the error "The import com.uviva.JustTesting cannot be resolved", trying with "import com.uviva.*" and "import com.uviva.JustTesting". As I said, the error only shows in the editor when I put the correct path in the @Libraries annotation, so it's something to do with the jar file itself, and not an issue with locating the jar.

I've enclosed my com.uviva jar - there is a method com.uviva.JustTesting.getString() which returns "Success!".

I really would love to solve this - I'm using the Historical Tester so need to get some of my SDK code working inside JForex as cleanly as possible.


Attachments:
uviva.zip [553 Bytes]
Downloaded 75 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: Problem including library into JForex strategy Post rating: 0   New post Posted: Tue 12 Dec, 2017, 21:29 

User rating: 2
Joined: Thu 07 Nov, 2013, 12:15
Posts: 121
PS - to be sure that it's not the IDE doing something automagical in the background, I just compiled a single class jar with the command:

c:\Program Files\Java\jdk1.8.0_121\bin\jar.exe" cvf util.jar JustTesting.class

Still not working :( :(


 
 Post subject: Re: Problem including library into JForex strategy Post rating: 0   New post Posted: Wed 13 Dec, 2017, 09:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
There was a problem with uviva.jar.
JustTesting must be put in directory inside of the jar. The directory must be equal to class package: com/uviva/JustTesting.class


Attachments:
uviva2.zip [1.27 KiB]
Downloaded 69 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: Problem including library into JForex strategy Post rating: 0   New post Posted: Wed 13 Dec, 2017, 17:04 

User rating: 2
Joined: Thu 07 Nov, 2013, 12:15
Posts: 121
Made it!

I suspect you were right and I wasn't building the jar in a way that preserved the directory structure. I'd tried using the command line and a bare-bones IDE, but googling for info on how to do it is confusing.

So this time I set up a project in IntelliJ IDEA and used their artifact feature, and it worked!

Thanks for sticking with me on this - much appreciated.


 

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