3

i am using gradle project for log4j2... and i am getting following error while creating csvlayout: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat

CsvParameterLayoutExample class

package log4j_tutorial;
import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;

public class CsvParameterLayoutExample {

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

public static void main(String[] args) {
    int val1 = 10, val2 = 11, val3 = 12;
    logger.trace("Trace Message!", val1, val2, val3);
    logger.debug("Debug Message!", val1, val2, val3);
    logger.info("Info Message!", val1, val2, val3);
    logger.warn("Warn Message!", val1, val2, val3);
    logger.error("Error Message!", val1, val2, val3);
    logger.fatal("Fatal Message!", val1, val2, val3);
}

}

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" xmlns="http://logging.apache.org/log4j/2.0/config" packages="log4j_tutorial">
<Appenders>
<File name="my_file_appender"  fileName="C:/Users/bishal.gupta/Desktop/Testing/CsvLog4jTest/application.log">
<CsvParameterLayout delimiter=","/>
</File>
</Appenders>

<Loggers>
   <Root level="info">
       <AppenderRef ref="my_file_appender" />
   </Root>
</Loggers>
</Configuration>

build.gradle for dependencies

Exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethods(Class.java:1808)
at     org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:149)
at   org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:119)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:888)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:828)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:820)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:820)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:449)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:197)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:209)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:492)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:562)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:578)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:214)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:145)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:182)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:455)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:441)
at log4j_tutorial.CsvParameterLayoutExample.<clinit>(CsvParameterLayoutExample.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.csv.CSVFormat
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 22 more

i got stuck from morning ... :(

2 Answers 2

2

you have to add commons-csv as a dependency.

If you use gradle as your question is tagged, add these line:

// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.4'
Sign up to request clarification or add additional context in comments.

8 Comments

thnx for quick reply... i tried this in gradle but dont know why gradle was not downloading this jar... :( so i added externally... can you tell me y gradle is not downloading
@BishalGupta If the jar is not downloaded, you should get a message when you run gradle
no i am not getting any message... After building gradle when i see my build path ... there is no such commons-csv.jar file
@can you shou your build file?
dependencies { compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'compile 'org.apache.logging.log4j:log4j-web:2.5' testCompile 'org.springframework:spring-test:'+deps.springVersion compile group: 'org.apache.commons', name: 'commons-csv', version: '1.4' }
|
-1

build.gradle was not able to download the jar i mentioned:

build.gradle : "compile 'org.apache.commons:commons-csv:1.1"

So i download the commons-csv jar from below link and added externally into the project

commons-csv.jar

binaries: commons-csv-1.4-bin.zip

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.