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.

External Classes in jar files
 Post subject: External Classes in jar files Post rating: 0   New post Posted: Thu 02 Jul, 2009, 09:39 

User rating: 0
Joined: Thu 02 Jul, 2009, 09:25
Posts: 5
I am running a strategy that uses a jar file to run external classes. I have a superclass of strategy to save time in creating similar strategies.
package jforex;

import main.MasterStrategy;

import com.dukascopy.api.*;

@Library("C:\\Program Files\\Java\\javamail-1.4.2\\lib\\mailapi.jar;C:\\Program Files\\Java\\javamail-1.4.2\\lib\\smtp.jar;C:\\javasource\\main.jar")
public class MyStrategyB5Dfb30 extends MasterStrategy {
.
.
.



Where MasterStrategy looks something like this:

package main;

import com.dukascopy.api.*;

import java.util....;

public abstract class MasterStrategy implements IStrategy {
.
.
.


This was running fine up until now.
However I added a new class that is compiled in to the jar file. I have tested it individually so I know that it works outside of jforex. But whenever I run it in the jforex client, I compile ok and then get the run time error
java.lang.NoClassDefFoundError: main/ExternalClass @ main.MasterStrategy.onStart(MasterStrategy.java:134)


where onStart in Master Strategy looks like this

public void onStart(IContext context) throws JFException {
...

        ExternalClass external = new ExternalClass(...);
...
}


This is what the error on line 134 is referring to.

Does anyone know what I have done wrong?
Thanks
Rob


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Thu 02 Jul, 2009, 10:36 

User rating: 0
Joined: Thu 02 Jul, 2009, 09:25
Posts: 5
So its seems that I have found the problem.
There was an additional classs that was imported in to my ExternalClass, that was not included in the package.
As the jars are precompiled I did not get a compilation error but a run time error.
I found this out by trying to import my class directly from the jar file in a new clean strategy.
Then I got the compilation errors and realised that I was missing the files in the jar.

Contact me if you are having this problem and don't follow my solution


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Tue 17 Jan, 2012, 17:22 

User rating: 0
Joined: Tue 17 Jan, 2012, 17:04
Posts: 2
Hi

I have similarly errors with @Library. I tried a simple Ping/Pong application with akka actors. Outside JForex all works fine, but if the client is inside JForex it not works. That is the code of the client: https://pastebin.com/SvFQ22TT. It's a very simple JForex Strategy that use akka actors and plays ping pong with a server outside of JForex. I used 5 jar files:

@RequiresFullAccess
@Library("akka-actor-2.0-M2.jar:akka-remote-2.0-M2.jar:netty-3.2.6.Final.jar:protobuf-java-2.4.1.jar:scala-library-2.9.1.jar")


But, I get always the errors below. It seems, that a class is not loaded correctly. Outside JForex the client works fine. I had in the classpath exactly the same like in JForex. The missing definition org/jboss/netty/akka/util/Timer (wrong name: akka/util/Timer) exists in the file: akka-actor-2.0-M2.jar. So, it is not really missing. It must be either a bug in JForex or I did anything wrong.
17.01.2012 16:49:49.517   SEVERE                            a.c ] org/jboss/netty/akka/util/Timer (wrong name: akka/util/Timer)
java.lang.NoClassDefFoundError: org/jboss/netty/akka/util/Timer (wrong name: akka/util/Timer)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
   at com.dukascopy.dds2.greed.agent.a.c.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
   at com.dukascopy.dds2.greed.agent.a.c.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
   at com.dukascopy.dds2.greed.agent.a.c.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
   at com.dukascopy.dds2.greed.agent.a.c.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
   at akka.actor.ActorSystemImpl.createScheduler(ActorSystem.scala:417)
   at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:333)
   at akka.actor.ActorSystem$.apply(ActorSystem.scala:46)
   at akka.actor.ActorSystem$.create(ActorSystem.scala:45)
   at akka.actor.ActorSystem.create(ActorSystem.scala)
   at jforex.JfxPing$ServerListener.run(JfxPing.java:138)
   at java.lang.Thread.run(Thread.java:619)
17.01.2012 16:49:49.541   SEVERE                            a.c ] org/jboss/netty/akka/util/Timeout (wrong name: akka/util/Timeout)
java.lang.NoClassDefFoundError: org/jboss/netty/akka/util/Timeout (wrong name: akka/util/Timeout)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
   at com.dukascopy.dds2.greed.agent.a.c.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
   at com.dukascopy.dds2.greed.agent.a.c.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
   at akka.actor.ActorSystemImpl.createScheduler(ActorSystem.scala:417)
   at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:333)
   at akka.actor.ActorSystem$.apply(ActorSystem.scala:46)
   at akka.actor.ActorSystem$.create(ActorSystem.scala:45)
   at akka.actor.ActorSystem.create(ActorSystem.scala)
   at jforex.JfxPing$ServerListener.run(JfxPing.java:138)
   at java.lang.Thread.run(Thread.java:619)
17.01.2012 16:49:49.790   SEVERE                            a.c ] Uncaught exception in [Thread-152] thread: No configuration setting found for key 'akka.remote.failure-detector.threshold'
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.remote.failure-detector.threshold'
   at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:112)
   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:134)
   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:137)
   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:137)
   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:105)
   at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:143)
   at com.typesafe.config.impl.SimpleConfig.getConfigNumber(SimpleConfig.java:158)
   at com.typesafe.config.impl.SimpleConfig.getInt(SimpleConfig.java:169)
   at akka.remote.RemoteSettings.<init>(RemoteExtension.scala:20)
   at akka.remote.RemoteActorRefProvider.<init>(RemoteActorRefProvider.scala:32)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at akka.util.ReflectiveAccess$$anonfun$createInstance$1.apply(ReflectiveAccess.scala:24)
   at akka.util.ReflectiveAccess$$anonfun$createInstance$1.apply(ReflectiveAccess.scala:18)
   at akka.util.ReflectiveAccess$.withErrorHandling(ReflectiveAccess.scala:106)
   at akka.util.ReflectiveAccess$.createInstance(ReflectiveAccess.scala:18)
   at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:361)
   at akka.actor.ActorSystem$.apply(ActorSystem.scala:46)
   at akka.actor.ActorSystem$.create(ActorSystem.scala:45)
   at akka.actor.ActorSystem.create(ActorSystem.scala)
   at jforex.JfxPing$ServerListener.run(JfxPing.java:138)
   at java.lang.Thread.run(Thread.java:619)


Thanks in advance
dl3r


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Wed 18 Jan, 2012, 09:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
dl3r wrote:
Outside JForex the client works fine.
If your standalone project has those libraries in classpath, then it will work regardless if you have the @Library annotation or not.
dl3r wrote:
inside JForex it not works
Have you tried using full paths to jar files?


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Wed 18 Jan, 2012, 11:48 

User rating: 0
Joined: Tue 17 Jan, 2012, 17:04
Posts: 2
API Support wrote:
dl3r wrote:
inside JForex it not works
Have you tried using full paths to jar files?

I have now tried with full paths but have the same errors. I don't know why, I have especially written a duplicate app. One standalone and one for JForex with exactly the same code. The standalone app run fine but if I use the same code inside JForex strategy I got this errors. But well, I have now changed anyway the API. Instead of akka actors I use now JBoss Netty. This work for me and has lesser dependencies.


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Sun 28 Dec, 2014, 12:43 

User rating: 1
Joined: Mon 16 Jul, 2012, 04:14
Posts: 31
hi support. I created a library ind.jar using Eclipse. Next, using directives @Library (" ind.jar ") to include it. But the error message "09:54:53 The attribute value is undefined for the annotation type Library". What is the reason? Sincerely, Alex.


 
 Post subject: Re: External Classes in jar files Post rating: 0   New post Posted: Mon 05 Jan, 2015, 10:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Are you sure that you are using com.dukascopy.api.Library annotation? Check your imports.


 

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