从JAR执行时NoClassDefFoundError + ClassNotFoundException

时间:2017-05-24 08:22:49

标签: java bash intellij-idea noclassdeffounderror classnotfoundexception

当我从bash作为JAR运行时,我的程序有一个例外,但不是从IntelliJ运行。出了什么问题?

Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
        at EndUserHandbook.getLinkList(EndUserHandbook.java:53)
        at EndUserHandbook.main(EndUserHandbook.java:24)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
        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)
        ... 2 more

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>end-user-handbook</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.2-FINAL</version>
        </dependency>

        <dependency>
            <!-- jsoup HTML parser library @ http://jsoup.org/ -->
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.10.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

    </dependencies>


</project>

清单:

Manifest-Version: 1.0
Main-Class: EndUserHandbook

1 个答案:

答案 0 :(得分:0)

你是如何推出你的计划的?启动jar文件的方法是java -jar file.jarjava file.jar无效。