35

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:

ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66
  • How exactly are you running it? – Jon Skeet Feb 13 '15 at 16:31
  • I got this error for selenium, i noticed that i added some files manually & some with maven, wich caused this error.. So probably a problem with the compatibility between selenium and htmlDriver (in my case) – bieboebap Sep 04 '18 at 12:22

6 Answers6

38

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.

azurefrog
  • 10,785
  • 7
  • 42
  • 56
  • which dependency is it? – Gobliins Oct 23 '15 at 13:42
  • @Gobliins The [apache commons-lang](http://commons.apache.org/proper/commons-lang/) home page has instructions to download it directly, or include it as a maven dependency. – azurefrog Oct 23 '15 at 14:46
  • ah yes i found it i forgot to remove the comment sry – Gobliins Oct 23 '15 at 14:52
  • I have 3.3.2 of commons-lang3 in pom. This did not solve the issue. I still get java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils. Here is the code which has this error if (StringUtils.equals(blah.getHaha().getLaugh(), "hehe")). – MBK Jan 19 '16 at 02:35
  • @MBK In the comments here isn't a great place to try to ask a question. If this answer didn't help you, it may be because you have a different problem than the OP. Try posting your own question, including your code and pom.xml. – azurefrog Jan 19 '16 at 03:15
  • Thanks, @azurefrog. The provided solution worked for me. Cheers!! – Vikash Choudhary Nov 16 '19 at 06:57
16

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.12</version>
</dependency>

Don't forget: Update Maven Project


Apache Commons Lang ™ Dependency Information

Last Published: 2 March 2021 | Version: 3.12

Apache Maven

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

Apache Buildr

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

Apache Ivy

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

Groovy Grape

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

Gradle/Grails

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

Scala SBT

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

Leiningen

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

Reference:

ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
2

Yo adding the below and update maven project worked like a charm:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.1</version>
</dependency>
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
kiran
  • 131
  • 1
  • 4
1

Adding below worked for me:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
smita
  • 43
  • 1
  • 8
0

When everything else is correct, rarely jar file gets corrupted. Ensure you don't see error something like below while compiling

[ERROR] error reading 
C:\Users\Mohan\.m2\repository\org\apache\commons\commons-lang3\3.7\commons-lang3-3.7.jar; 
ZipFile invalid LOC header (bad signature)
Mohan Narayanaswamy
  • 2,149
  • 6
  • 33
  • 40
0

I was having this issue in IJ version 2016 after updating it to 2018.3.4 and clicking "Generate sources and update folders for all projects" at Maven options tab the issue went away

IJ Maven tab at IJ 2018.3.4

Shell_Leko
  • 512
  • 5
  • 13