0

I am writing a calculator that loads all the classes needed through maven dependencies dynamically.such as slf4j,... but i have a problem.since i don't want to set my class path to manifest,my customClassLoader does it itself. but my logger is a private static final field and JVM want to load it before i call my customClassLoader and i get error!what can i do?

public class Calculator{

private List<String> expressions = new ArrayList<String>() ;
private List<String> results = new ArrayList<String>();
private final Logger logger = LoggerFactory.getLogger(Calculator.class);
public Calculator(){
    //System.out.println("HELLO");
    OperatorsCatalog catalog = new OperatorsCatalog();
}
public void calculate(String inputaddress){
    //this.loadAddedClasses();
    try{
        logger.debug("Start to read the input file");
        this.read(inputaddress);
        logger.info("Input file is read");

        for(int i = 0;i<expressions.size();i++){
            ExpressionCalculator e = new ExpressionCalculator(expressions.get(i),OperatorsCatalog.getKnownOperators());
            e.evaluate();
            results.add(e.getResult());

        }
        logger.info("All evaluations ended");
        logger.debug("Writing to file started");
        this.write();

    }
    catch(FileNotFoundException  e){
        logger.warn("Can not find Input file",e);
    }
    catch(IOException er){
        logger.warn(er.getMessage());
    }

}
public void read(String inputaddress)throws FileNotFoundException,IOException{

    CustomReader reader = new CustomReader();
    expressions =reader.read(inputaddress);
}
public void write(){
    CustomWriter writer = new CustomWriter();
    writer.write(results);
}
/*public void loadAddedClasses(){

    CustomClassLoader classloader = new CustomClassLoader();
    classloader.loadClasses();

}*/
public static void main(String args[]) {
System.out.println("HELLO");
    CustomClassLoader classloader = new CustomClassLoader();
    classloader.loadClasses();
    Calculator calculator = new Calculator();
    calculator.calculate(args[0]);


}

}

PegahK
  • 105
  • 2
  • 11
  • Can you share some additional info? Your code doesn't provide enough insight to answer the question. I wonder what your `CustomClassLoader` does and whether this is really a `ClassLoader`. Right now it seems that your `Calculator` class is loaded by application class loader. The same one will be used to load all dependecy classes, so your class loader is not involved at all. Any reason not to have SLF4J API on your class path? – Aleh Maksimovich Oct 08 '17 at 10:43
  • that's right.my calculator is loaded by application class loader.using maven i copy all the dependencies into a lib folder.and my class loader loads them from that folder(using urlclassloader) – PegahK Oct 08 '17 at 11:36

0 Answers0