Eclipse Oxygen运行Java代码遇NoClassDefFoundError求助
Hey there, I’ve dealt with this exact headache when working with Exchange Web Services in Eclipse, so let’s break down what’s going on and fix it:
问题根源
That NoClassDefFoundError tells us a key detail: even though your import statements work fine (Eclipse can find the EWS classes at compile time), your runtime classpath is missing the Apache HttpClient dependencies that ExchangeService relies on. The HttpClientConnectionManager class is part of the Apache HttpClient library—this is a hidden dependency that your EWS JAR needs but isn’t included with it.
分步解决方案
Grab the required Apache HttpClient JARs
You need at least these two core JARs (make sure their versions match what your EWS library expects):httpclient.jarhttpcore.jar
If you’re unsure which versions to pick, check your EWS JAR’sMETA-INF/MANIFEST.MFfile—it’ll list the exact dependencies it requires.
Make sure Eclipse recognizes the JARs at runtime
Just copying JARs into yourlibfolder isn’t enough. You need to add them to the build path:- Right-click your project in the Package Explorer
- Hover over
Build Path> SelectAdd External Archives...(orAdd Libraries...if you’ve already moved the JARs into your project’s lib folder) - Navigate to the HttpClient JARs you downloaded and add them
- Confirm they show up under
Referenced Librariesin your project
Clean and rebuild your project
Eclipse’s build cache can sometimes cause weird classpath glitches:- Go to
Project>Clean... - Select your project and click
OK - Let the rebuild finish, then run your test class again
- Go to
Check for version mismatches
Older EWS versions often depend on specific Apache HttpClient versions (like 4.5.x instead of the latest 5.x). If you mixed a new HttpClient JAR with an old EWS JAR, this mismatch will trigger class-not-found errors. Stick to the dependency versions recommended by your EWS library.
你的代码参考
package com.ed; import microsoft.exchange.webservices.data.core.ExchangeService; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub ExchangeService service = new ExchangeService(); } }
错误信息回顾
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
at com.ed.Test.main(Test.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.HttpClientConnectionManager
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)
... 1 more
内容的提问来源于stack exchange,提问作者David Jones

