运行时NoClassDefFoundError

在使用gradle build项目之后,我在运行时收到错误“NoClassDefFoundError”。

该程序确实开始,一切似乎一直工作,直到它应该读取一些PDF文件,然后我收到一个没有发现异常的类。 当我在intellij中调试我的应用程序时,一切正常。

当我解压缩jar文件时,我发现没有包含PDFFile.class 。 当我在Linux上构建相同的项目时奇怪,我没有这个问题。

 java.lang.NoClassDefFoundError: PDFFile at PDFViewModel$loadPdfList$1.invoke(GUI.kt:107) at PDFViewModel$loadPdfList$1.invoke(GUI.kt:87) at tornadofx.FXTask.call(Lib.kt:219) at javafx.concurrent.Task$TaskCallable.call(Task.java:1423) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: PDFFile at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 6 more 

我确实已经定义了PDFFile。

 data class PDFFile(val path: String, val name: String, var pages: Int?, var progress: Int?) class PDFViewModel : ItemViewModel<PDFFile>() { val pdfFiles = SimpleObjectProperty<ObservableList<PDFFile>>() private val files = mutableListOf<PDFFile>() fun loadPdfList() { files.clear() val pdfPath = File(cfg.getProperty("pdf_path")) if (pdfPath.isDirectory) { val pdfList = pdfPath.listFiles().filter { FilenameUtils.getExtension(it.name).toLowerCase() == "pdf" } runAsync { // Set progress to 0 just in case directory is empty updateProgress(0.0, 1.0) if (pdfList.isNotEmpty()) { pdfList.forEachIndexed { index, file -> updateMessage("Loading ${file.name}") // Load basic data about pdf files PDDocument.load(file.absoluteFile).use { document -> files.add(PDFFile(file.absolutePath, file.nameWithoutExtension, document.numberOfPages, 0)) updateProgress((index + 1.0), pdfList.size.toDouble()) } } } } ui { pdfFiles.set(files.observable()) } } } } 

在我添加的gradle.build文件中:

 jar { manifest { attributes 'Implementation-Version': version, 'Main-Class': 'PDFStripApp' } from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } 

我在另一个名为PdfFile文件中有一个类,在Linux中,因为文件系统区分大小写,所以没有任何问题。 在Windows中, PDFFile.classPdfFile.class是相同的东西,因此没有正确地结束在jar文件。