gradle build
を使用してプロジェクトをビルドした後、実行時にエラー "NoClassDefFoundError"が表示されます。NoClassDefFoundError at runtime
プログラムが起動し、いくつかの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) } }
}