NoClassDefFoundError:org / apache / commons / lang3 / StringUtils

时间:2015-02-13 16:27:56

标签: java apache

我试图运行使用此library的示例pcsc项目。

运行时我收到以下错误

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
  

我添加了commons-lang-2.6.jar&amp; commons-lang3-3.1-sources.jar in   libs和类路径也。我仍然收到此错误

代码

public static void main(final String[] args) throws CardException, CommunicationException {


    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);
    }

}

我已经提到了以下链接:

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

请帮忙!

6 个答案:

答案 0 :(得分:17)

  

我添加了commons-lang-2.6.jar&amp;公地lang3-3.1-sources.jar ...

以下是您的问题:commons-lang-2.6.jar不包含org.apache.commons.lang3个包,因为它是版本3的一部分,commons-lang3-3.1-sources.jar包含来源代码,而不是字节代码。

您需要包含commons-lang3-3.1.jar

答案 1 :(得分:6)

如果您正在使用 Maven 将此内容放入pom.xml:

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

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

别忘了更新项目

Apache Commons Lang™依赖信息 - 最新版本3.8(发布日期:2018年8月20日)

Apache Maven

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

摇篮/ Grails的

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

Apache Buildr

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

Apache Ivy

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

Groovy Grape

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

Scala SBT

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

Leiningen

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

参考:

https://commons.apache.org/proper/commons-lang/dependency-info.html

答案 2 :(得分:2)

Yo添加了以下内容并更新了maven pronject就像一个魅力

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

答案 3 :(得分:0)

当其他一切都正确时,很少有jar文件被破坏。确保在编译时不会看到类似下面的错误

[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)

答案 4 :(得分:0)

将IJ版本更新到2018.3.4,然后在Maven选项选项卡上单击“生成所有项目的源和更新文件夹”后,我遇到了这个问题。

IJ Maven tab at IJ 2018.3.4

答案 5 :(得分:0)

添加以下内容对我有用

   <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-math3</artifactId>
                <version>3.6.1</version>
     </dependency>