-1

我的程序在從bash運行而不是IntelliJ運行時出現JAR異常。出了什麼問題?NoClassDefFoundError + ClassNotFoundException從JAR執行時

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 
+0

告訴我們什麼是你的依賴項標籤,除了pom。你是否在自己的jar或類路徑中添加了lib jar –

+0

@RaviParekh我更新了一個完整的pom – santafebound

回答

0

你是如何啓動你的計劃嗎?啓動jar文件的方式是java -jar file.jarjava file.jar不起作用。

+0

這正是我發佈它的原因。 ''java -jar file.jar''。 – santafebound

+0

你可以嘗試添加'編譯'到你的依賴關係嗎?根據[本主題](https://stackoverflow.com/questions/12811392/java-classnotfoundexception-with-maven-dependency),它應該工作。 – Abrikot

相關問題