简体   繁体   English

Java-具有指定类路径的NoClassDefFound错误

[英]Java - NoClassDefFound error with specified classpath

When I try to run my jar application, I get a NoClassDefFoundError even though i have referenced the library containing the class in my classpath. 当我尝试运行jar应用程序时,即使我在类路径中引用了包含类的库,也遇到了NoClassDefFoundError。

This is the line causing it (in the start method of a thread): 这是导致它的行(在线程的start方法中):

Spark.staticFiles.location("/public");

This defines the location of static files for the Spark framework for java, and I have the spark library in the "lib" folder. 这定义了Java Spark框架的静态文件的位置,并且我在“ lib”文件夹中有spark库。 The libraries are included in the jar: lib package in the jar 这些库包含在jar中:jar中的lib包

My manifest file looks like this: 我的清单文件如下所示:

Manifest-Version: 1.0 清单版本:1.0

Class-Path: lib/ * 类路径:lib / *

Main-Class: com.xx.xx.xx.Main 主要类别:com.xx.xx.xx.Main

This should as far as I know mean that all libraries in lib is included, but if i run the jar with a simple java -jar test.jar i get this: 据我所知,这意味着包括lib中的所有库,但是如果我使用简单的java -jar test.jar运行jar,则会得到以下信息:

Exception in thread "Thread-2" java.lang.NoClassDefFoundError: spark/Spark
    at com.xx.xx.xx.Main.run(TundraWebApp.java:20)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: spark.Spark
    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

spark/Spark being part of one of the libraries. spark / Spark是其中一个库的一部分。

Why isn't my libraries detected? 为什么未检测到我的库?

I don't think Class-Path supports wildcards. 我不认为Class-Path支持通配符。 You'd have to spell out the jar names, eg: 您必须拼出jar名称,例如:

Class-Path: libs/spark-core_2.11-2.3.0.jar libs/spark-sql_2.11-2.3.0.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM