Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: org/apache/commons/lang3/StringUtils

I'm trying to run the sample project with this library and I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: 

    org/apache/commons/lang3/StringUtils

    at com.github.devnied.emvnfccard.enums.EmvCardScheme.<init>(EmvCardScheme.java:97)
    at com.github.devnied.emvnfccard.enums.EmvCardScheme.<clinit>(EmvCardScheme.java:32)
    at com.github.devnied.emvnfccard.parser.EmvParser.readWithAID(EmvParser.java:277)
    at com.github.devnied.emvnfccard.parser.EmvParser.readEmvCard(EmvParser.java:120)
    at com.github.devnied.emvpcsccard.Main.main(Main.java:64)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

I've added commons-lang-2.6.jar & commons-lang3-3.1-sources.jar in libs and classpath

Main class:

public static void main(final String[] args) throws CardException {
    Main pcsc = new Main();
    CardTerminal ct = pcsc.selectCardTerminal();
    Card c = null;
    if (ct != null) {
        c = pcsc.establishConnection(ct);
        CardChannel channel = c.getBasicChannel();
        PcscProvider provider = new PcscProvider(channel);
        EmvParser parser = new EmvParser(provider, false);
        parser.readEmvCard();
        c.disconnect(false);
    }
}

I have referred to the following links:

  • java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils from BaseClassLoader

  • Struts 2 framework demo

  • http://apache-commons.680414.n4.nabble.com/lang-java-lang-NoClassDefFoundError-org-apache-commons-lang-StringUtils-Exception-td3735881.html

like image 813
Rachita Nanda Avatar asked Feb 13 '15 16:02

Rachita Nanda


Video Answer


4 Answers

I have added commons-lang-2.6.jar & commons-lang3-3.1-sources.jar...

Here's your problem: commons-lang-2.6.jar doesn't contain the org.apache.commons.lang3 package, since that's part of version 3, and commons-lang3-3.1-sources.jar contains the source code, not the byte code.

You need to include commons-lang3-3.1.jar instead.

like image 151
azurefrog Avatar answered Oct 11 '22 11:10

azurefrog


If you're using Maven, put this inside your pom.xml file:

Maven Central Repository for Commons Lang:

<dependency>     <groupId>commons-lang</groupId>     <artifactId>commons-lang</artifactId>     <version>2.6</version> </dependency> 

Maven Central Repository for Apache Commons Lang:

<dependency>     <groupId>org.apache.commons</groupId>     <artifactId>commons-lang3</artifactId>     <version>3.11</version> </dependency> 

Don't forget: Update Maven Project


Apache Commons Lang ™ Dependency Information

Last Published: 30 August 2020 | Version: 3.11

Apache Maven

<dependency>   <groupId>org.apache.commons</groupId>   <artifactId>commons-lang3</artifactId>   <version>3.11</version> </dependency> 

Apache Buildr

'org.apache.commons:commons-lang3:jar:3.11' 

Apache Ivy

<dependency org="org.apache.commons" name="commons-lang3" rev="3.11">   <artifact name="commons-lang3" type="jar" /> </dependency> 

Groovy Grape

@Grapes( @Grab(group='org.apache.commons', module='commons-lang3', version='3.11') ) 

Gradle/Grails

compile 'org.apache.commons:commons-lang3:3.11' 

Scala SBT

libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.11" 

Leiningen

[org.apache.commons/commons-lang3 "3.11"] 

Reference:

  • https://commons.apache.org/proper/commons-lang/dependency-info.html
like image 23
ℛɑƒæĿᴿᴹᴿ Avatar answered Oct 11 '22 10:10

ℛɑƒæĿᴿᴹᴿ


Yo adding the below and update maven pronject worked like a charm

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>

like image 32
kiran Avatar answered Oct 11 '22 10:10

kiran


Adding below worked for me

   <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-math3</artifactId>
                <version>3.6.1</version>
     </dependency>
like image 24
smita Avatar answered Oct 11 '22 11:10

smita