javaubuntuloggingterminalcompiler-errors

Compiling Java program in terminal causes log error


I am trying to compile a Java program in the terminal:

Long version containing all the imports:

javac -classpath bin:$OSPL_HOME/jar/dcpssaj5.jar:$OSPL_HOME/jar/dcpssaj5-sources.jar:$OSPL_HOME/jar/dcpssaj-osgi-bundle.jar:$OSPL_HOME/jar/dcpssaj-sources.jar:$OSPL_HOME/jar/dcpssaj.jar:$OSPL_HOME/jar/osplconf.jar:$OSPL_HOME/jar/tooling_common.jar:$OSPL_HOME/jar/dcpsprotobuf.jar:$OSPL_HOME/jar/cmdataadapter.jar:$OSPL_HOME/jar/cmapi.jar:$OSPL_HOME/jar/ddsface.jar:Libraries/httpclient-4.5.12.jar:Libraries/jersey-client-1.19.4.jar:Libraries/jersey-client-1.19.jar:Libraries/jersey-core-1.19.4.jar:Libraries/json-simple-1.1.1.jar:Libraries/json-simple-3.1.0.jar:Libraries/jsr311-api-1.1.1.jar:Libraries/mqtt-client-0.0.6.jar:Libraries/paho-mqtt-client-1.13.0.jar -sourcepath src/ src/afarcloud/Main/afarcloud_main.java

Without all the imports:

javac -classpath bin:(jar_files) -sourcepath src/ src/afarcloud/Main/afarcloud_main.java

I have added what I thought would be all the necessaries jars, however I get the following error related to a logger when I try to run the code on my Ubuntu computer:

src/afarcloud/Log/UtilLog.java:3: error: package org.apache.log4j does not exist
import org.apache.log4j.Logger;
                       ^
src/afarcloud/Log/UtilLog.java:7: error: cannot find symbol
    private static Logger log = Logger.getLogger(UtilLog.class);
                   ^
  symbol:   class Logger
  location: class UtilLog
src/afarcloud/Log/UtilLog.java:7: error: cannot find symbol
    private static Logger log = Logger.getLogger(UtilLog.class);
                                ^
  symbol:   variable Logger
  location: class UtilLog
src/afarcloud/Log/UtilLog.java:10: error: cannot find symbol
        log = Logger.getLogger(clase);
              ^
  symbol:   variable Logger
  location: class UtilLog
4 errors

What confuses me is that there is no folder called "Log" under src/afarcloud, so I am pretty confused about how to proceed... Any help is highly appreciated, thank you.


Solution

  • Looks that you're missing import statement. As a conclusion, all Logger Objects cannot be find and any new instances cant be created.

    Try to use import org.apache.log4j.Logger;.

    Or import via CLI. https://logging.apache.org/log4j/2.x/download.html