最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - NoClassDefFoundError and InvocationTargetException when using Apache HttpClient - Stack Overflow

programmeradmin2浏览0评论

I’m encountering an issue while using Apache HttpClient in a JavaFX application. When I click a button in the UI, I get a NoClassDefFoundError related to missing classes from Apache libraries. I’ve already added several JAR files, but the issue persists. Here are the details:

When running the application, I see the following error:

Подключение к базе данных успешно!
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at [email protected]/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1863)
    ...
Caused by: java.lang.NoClassDefFoundError: /apache/james/mime4j/message/Body
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    ...
Caused by: java.lang.ClassNotFoundException: .apache.james.mime4j.message.Body
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    ...

I HAVE THIS LIBS:

I use Eclipse, Java 23, and module system in my project, maybe its error 'cause i not add smth in module-info.java?

AND SO:

  1. Why am I getting a NoClassDefFoundError even though I’ve added all the required JAR files?

  2. Are there any additional libraries required for httpmime and httpclient to work properly?

  3. How can I correctly configure the classpath in Eclipse to avoid such errors?

UPDATE:

/home/asl/.p2/pool/plugins/.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_23.0.2.v20250131-0604/jre/bin/java
-Dfile.encoding=UTF-8
-Dstdout.encoding=UTF-8
-Dstderr.encoding=UTF-8
-p /home/asl/eclipse-workspace/VK_SENDER/bin:/home/asl/.p2/pool/plugins/.eclipse.fx.ide.css.jfx8_3.10.0.202303150700.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.base.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.controls.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.fxml.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.graphics.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.media.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.swing.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.web.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx-swt.jar:/home/asl/libs/commons-logging-1.2.jar:/home/asl/libs/httpclient-4.5.13.jar:/home/asl/libs/httpcore-4.4.13.jar:/home/asl/libs/postgresql-42.7.5.jar:/home/asl/libs/sdk-1.0.14.jar:/home/asl/libs/fontawesomefx-8.9.jar:/home/asl/eclipse-workspace/VK_SENDER/apache-mime4j-core-0.8.10.jar:/home/asl/eclipse-workspace/VK_SENDER/httpmime-4.0-alpha4.jar
-XX:+ShowCodeDetailsInExceptionMessages
-m VK_SENDER/vksender.VkSender

I’m encountering an issue while using Apache HttpClient in a JavaFX application. When I click a button in the UI, I get a NoClassDefFoundError related to missing classes from Apache libraries. I’ve already added several JAR files, but the issue persists. Here are the details:

When running the application, I see the following error:

Подключение к базе данных успешно!
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at [email protected]/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1863)
    ...
Caused by: java.lang.NoClassDefFoundError: /apache/james/mime4j/message/Body
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    ...
Caused by: java.lang.ClassNotFoundException: .apache.james.mime4j.message.Body
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    ...

I HAVE THIS LIBS:

I use Eclipse, Java 23, and module system in my project, maybe its error 'cause i not add smth in module-info.java?

AND SO:

  1. Why am I getting a NoClassDefFoundError even though I’ve added all the required JAR files?

  2. Are there any additional libraries required for httpmime and httpclient to work properly?

  3. How can I correctly configure the classpath in Eclipse to avoid such errors?

UPDATE:

/home/asl/.p2/pool/plugins/.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_23.0.2.v20250131-0604/jre/bin/java
-Dfile.encoding=UTF-8
-Dstdout.encoding=UTF-8
-Dstderr.encoding=UTF-8
-p /home/asl/eclipse-workspace/VK_SENDER/bin:/home/asl/.p2/pool/plugins/.eclipse.fx.ide.css.jfx8_3.10.0.202303150700.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.base.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.controls.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.fxml.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.graphics.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.media.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.swing.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx.web.jar:/home/asl/libs/javafx-sdk-23.0.2/lib/javafx-swt.jar:/home/asl/libs/commons-logging-1.2.jar:/home/asl/libs/httpclient-4.5.13.jar:/home/asl/libs/httpcore-4.4.13.jar:/home/asl/libs/postgresql-42.7.5.jar:/home/asl/libs/sdk-1.0.14.jar:/home/asl/libs/fontawesomefx-8.9.jar:/home/asl/eclipse-workspace/VK_SENDER/apache-mime4j-core-0.8.10.jar:/home/asl/eclipse-workspace/VK_SENDER/httpmime-4.0-alpha4.jar
-XX:+ShowCodeDetailsInExceptionMessages
-m VK_SENDER/vksender.VkSender
Share Improve this question edited Mar 6 at 16:34 AslanPAPA asked Mar 6 at 9:06 AslanPAPAAslanPAPA 1331 silver badge3 bronze badges 3
  • Don't ask multiple questions in one. – aled Commented Mar 6 at 11:00
  • @Abra so and which command line VM arguments or Programm arguments ? P.S: They both is empty. – AslanPAPA Commented Mar 6 at 11:36
  • I am referring to this. – Abra Commented Mar 6 at 12:14
Add a comment  | 

1 Answer 1

Reset to default 0

.apache.james.mime4j.message.Body is not present in apache-mime4j-core. You needed apache-mime4j-assembly.

You can expand the nodes for the jars in the tree shown and verify what classes are and aren't actually present. NoClassDefFoundError means that it's not present at runtime. Looking in the jar itself would have shown you that it's not there at development time, either.

发布评论

评论列表(0)

  1. 暂无评论