Dukascopy
 
 
Wiki JStore Search Login

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

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

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

JFX compiler won't let me use log4j 2
 Post subject: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Tue 27 May, 2014, 16:44 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello support,

I want to log with log4j but when compiling my strategy for the JForex client the console says this.
java.lang.ExceptionInInitializerError
   at org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:71)
   at org.apache.logging.log4j.util.PropertiesUtil.<clinit>(PropertiesUtil.java:31)
   at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:48)
   at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:44)
   at Prototypes.TimeTrading.<clinit>(TimeTrading.java:92)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.f.aL(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.e.b(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.e.a(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.e.a(Unknown Source)
   at com.dukascopy.dds2.greed.util.d.a(Unknown Source)
   at com.dukascopy.dds2.greed.actions.servicesources.CompileStrategyAction.Ci(Unknown Source)
   at com.dukascopy.dds2.greed.actions.c.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
   at java.security.AccessControlContext.checkPermission(Unknown Source)
   at java.security.AccessController.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.lang.ClassLoader.checkClassLoaderPermission(Unknown Source)
   at java.lang.Thread.getContextClassLoader(Unknown Source)
   at org.apache.logging.log4j.util.ProviderUtil$1.run(ProviderUtil.java:93)
   at org.apache.logging.log4j.util.ProviderUtil$1.run(ProviderUtil.java:90)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.apache.logging.log4j.util.ProviderUtil.findClassLoader(ProviderUtil.java:89)
   at org.apache.logging.log4j.util.ProviderUtil.<clinit>(ProviderUtil.java:51)
... 17 more
27.05.2014 17:38:18.106   SEVERE                            a.e ] Cannot load target class
java.lang.Exception: Cannot load target class
   at com.dukascopy.dds2.greed.agent.a.e.b(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.e.a(Unknown Source)
   at com.dukascopy.dds2.greed.agent.a.e.a(Unknown Source)
   at com.dukascopy.dds2.greed.util.d.a(Unknown Source)
   at com.dukascopy.dds2.greed.actions.servicesources.CompileStrategyAction.Ci(Unknown Source)
   at com.dukascopy.dds2.greed.actions.c.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)



I see that this is not a problem of the jnlp file since there are all permission enabled.
Can you give me a hint how to bypass the security manager?

Thanks,
Juergen


 
 Post subject: Re: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Wed 28 May, 2014, 07:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Do you use @RequiresFullAccess? If not, could you please provide the example strategy?


 
 Post subject: Re: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Wed 28 May, 2014, 16:25 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

I figured it out, here is an example:

package com.jforex.programming.prototype;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Library;
import com.dukascopy.api.Period;
import com.dukascopy.api.RequiresFullAccess;

@RequiresFullAccess
@Library("D:/programs/libs/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar;D:/programs/libs/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar")
public class GapTrading implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    private final static Logger logger = LogManager.getLogger(GapTrading.class);

    @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
    }

    @Override
    public void onAccount(IAccount account) throws JFException {
    }

    @Override
    public void onMessage(IMessage message) throws JFException {
    }

    @Override
    public void onStop() throws JFException {
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


With the logger being static it does not work!!
Removing the static attribute and the strategy compiles. Do you know why?


 
 Post subject: Re: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Wed 28 May, 2014, 19:05 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

there is another issue with log4j2.
After compiling the console says:
ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger

Do you know where to put the log4j2.xml file to use the custom configuration?

Thanks,
Juergen


 
 Post subject: Re: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Fri 30 May, 2014, 12:02 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
FXjuxe wrote:
Do you know where to put the log4j2.xml file to use the custom configuration?
The configuration obviously has to be in the classpath. You could try to add an additional dependency library, that would contain this configuration file, though we are not sure if this would work. If that does not work, consider setting the logging configuration from your strategy.


 
 Post subject: Re: JFX compiler won't let me use log4j 2 Post rating: 0   New post Posted: Fri 30 May, 2014, 12:17 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
I already included the log4j2 in a separate library.
For those classes the logging works as expected.
Only the logger in the strategy file cannot be used.
My guess is that the resulting executable of the JavaFX compiler is not signed and therefore the security manager does not allow the loading of the needed log4j2 classes.

Thank you,
Juergen


 

Jump to:  

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