2017-10-10 109 views
2

在使用gradle build构建项目后,运行时收到错误“NoClassDefFoundError”。运行时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) } } 
} 

回答

2

我曾在一个名为因为文件系统PdfFile和Linux的其他文件中的类是区分大小写的,它没有任何问题有了这个。在窗口PDFFile.classPdfFile.class是相同的东西,因此没有正确的最终在jar文件。

相关问题