NoClassDefFoundError: org/apache/commons/lang3/StringUtils

我正在尝试使用此库运行示例项目,但收到以下错误:

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

我在libs和classpath中添加了commons-lang-2.6.jarcommons-lang3-3.1-sources.jar

主类:

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

我参考了以下链接:


答案 1

我已经添加了commons-lang-2.6.jar和commons-lang3-3.1-sources.jar...

这是你的问题:不包含包,因为这是版本3的一部分,并且包含源代码,而不是字节码。commons-lang-2.6.jarorg.apache.commons.lang3commons-lang3-3.1-sources.jar

您需要改为包含。commons-lang3-3.1.jar


答案 2

如果您使用的是 Maven,请将以下内容放在您的文件中:pom.xml

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>

不要忘记:更新Maven项目


Apache Commons Lang ™ Dependency Information

上次发布: 2020-08-30 |版本: 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'

阿帕奇常春藤

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

时髦葡萄

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

格雷德尔/圣杯

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

Scala SBT

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

莱宁根

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

参考:


推荐