{"id":7196,"date":"2024-04-11T23:01:01","date_gmt":"2024-04-11T15:01:01","guid":{"rendered":""},"modified":"2024-04-11T23:01:01","modified_gmt":"2024-04-11T15:01:01","slug":"java.NoClassDefF_\u600e\u4e48\u89e3\u51b3java.lang.NoclassDeffFoundError\u9519\u8bef","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7196.html","title":{"rendered":"java.NoClassDefF_\u600e\u4e48\u89e3\u51b3java.lang.NoclassDeffFoundError\u9519\u8bef"},"content":{"rendered":"
\u524d\u8a00<\/p>\n
\u5728\u65e5\u5e38Java\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u78b0\u5230java.lang.NoClassDefFoundError\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u9700\u8981\u82b1\u8d39\u5f88\u591a\u65f6\u95f4\u53bb\u627e\u9519\u8bef\u7684\u539f\u56e0\uff0c\u5177\u4f53\u662f\u54ea\u4e2a\u7c7b\u4e0d\u89c1\u4e86\uff1f\u7c7b\u660e\u660e\u8fd8\u5728\uff0c\u4e3a\u4ec0\u4e48\u627e\u4e0d\u5230\uff1f\u800c\u4e14\u6211\u4eec\u5f88\u5bb9\u6613\u628ajava.lang.NoClassDefFoundError\u548cjava.lang.ClassNotfoundException\u8fd9\u4e24\u4e2a\u9519\u8bef\u641e\u6df7\uff0c\u4e8b\u5b9e\u4e0a\u8fd9\u4e24\u4e2a\u9519\u8bef\u662f\u5b8c\u5168\u4e0d\u540c\u7684\u3002\u6211\u4eec\u5f80\u5f80\u82b1\u8d39\u65f6\u95f4\u53bb\u4e0d\u65ad\u5c1d\u8bd5\u4e00\u4e9b\u5176\u4ed6\u7684\u65b9\u6cd5\u53bb\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u6ca1\u6709\u771f\u6b63\u53bb\u7406\u89e3\u8fd9\u4e2a\u9519\u8bef\u7684\u539f\u56e0\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u901a\u8fc7\u89e3\u51b3NoClassDefFoundError\u9519\u8bef\u5904\u7406\u7684\u7ecf\u9a8c\u5206\u4eab\u6765\u63ed\u5f00NoClassDefFoundError\u7684\u4e00\u4e9b\u79d8\u5bc6\u3002NoClassDefFoundError\u7684\u9519\u8bef\u5e76\u975e\u4e0d\u80fd\u89e3\u51b3\u6216\u8005\u8bf4\u5f88\u96be\u89e3\u51b3\uff0c\u53ea\u662f\u8fd9\u79cd\u9519\u8bef\u7684\u8868\u73b0\u5f62\u5f0f\u5f88\u5bb9\u6613\u8ff7\u60d1\u5176\u4ed6\u7684Java\u5f00\u53d1\u8005\u3002\u4e0b\u9762\u6211\u4eec\u6765\u5206\u6790\u4e0b\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751fNoClassDefFoundError\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u4ee5\u53ca\u600e\u6837\u53bb\u89e3\u51b3\u8fd9\u4e2a\u9519\u8bef\u3002<\/p>\n
NoClassDefFoundError\u9519\u8bef\u53d1\u751f\u7684\u539f\u56e0<\/p>\n
NoClassDefFoundError\u9519\u8bef\u7684\u53d1\u751f\uff0c\u662f\u56e0\u4e3aJava\u865a\u62df\u673a\u5728\u7f16\u8bd1\u65f6\u80fd\u627e\u5230\u5408\u9002\u7684\u7c7b\uff0c\u800c\u5728\u8fd0\u884c\u65f6\u4e0d\u80fd\u627e\u5230\u5408\u9002\u7684\u7c7b\u5bfc\u81f4\u7684\u9519\u8bef\u3002\u4f8b\u5982\u5728\u8fd0\u884c\u65f6\u6211\u4eec\u60f3\u8c03\u7528\u67d0\u4e2a\u7c7b\u7684\u65b9\u6cd5\u6216\u8005\u8bbf\u95ee\u8fd9\u4e2a\u7c7b\u7684\u9759\u6001\u6210\u5458\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u8fd9\u4e2a\u7c7b\u4e0d\u53ef\u7528\uff0c\u6b64\u65f6Java\u865a\u62df\u673a\u5c31\u4f1a\u629b\u51faNoClassDefFoundError\u9519\u8bef\u3002\u4e0eClassNotFoundException\u7684\u4e0d\u540c\u5728\u4e8e\uff0c\u8fd9\u4e2a\u9519\u8bef\u53d1\u751f\u53ea\u5728\u8fd0\u884c\u65f6\u9700\u8981\u52a0\u8f7d\u5bf9\u5e94\u7684\u7c7b\u4e0d\u6210\u529f\uff0c\u800c\u4e0d\u662f\u7f16\u8bd1\u65f6\u53d1\u751f\u3002\u5f88\u591aJava\u5f00\u53d1\u8005\u5f88\u5bb9\u6613\u5728\u8fd9\u91cc\u628a\u8fd9\u4e24\u4e2a\u9519\u8bef\u641e\u6df7\u3002<\/p>\n
\u7b80\u5355\u603b\u7ed3\u5c31\u662f\uff0cNoClassDefFoundError\u53d1\u751f\u5728\u7f16\u8bd1\u65f6\u5bf9\u5e94\u7684\u7c7b\u53ef\u7528\uff0c\u800c\u8fd0\u884c\u65f6\u5728Java\u7684classpath\u8def\u5f84\u4e2d\uff0c\u5bf9\u5e94\u7684\u7c7b\u4e0d\u53ef\u7528\u5bfc\u81f4\u7684\u9519\u8bef\u3002\u53d1\u751fNoClassDefFoundError\u9519\u8bef\u65f6\uff0c\u4f60\u80fd\u770b\u5230\u5982\u4e0b\u7684\u9519\u8bef\u65e5\u5fd7\uff1a<\/p>\n
Exception in thread \"main\" java.lang.NoClassDefFoundError<\/p>\n
1<\/p>\n
\u9519\u8bef\u7684\u4fe1\u606f\u5f88\u660e\u663e\u5730\u6307\u660emain\u7ebf\u7a0b\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u7684\u7c7b\uff0c\u800c\u8fd9\u4e2amain\u7ebf\u7a0b\u53ef\u80fd\u65f6\u4e3b\u7ebf\u7a0b\u6216\u8005\u5176\u4ed6\u5b50\u7ebf\u7a0b\u3002\u5982\u679c\u662f\u4e3b\u7ebf\u7a0b\u53d1\u751f\u9519\u8bef\uff0c\u7a0b\u5e8f\u5c06\u5d29\u6e83\u6216\u505c\u6b62\uff0c\u800c\u5982\u679c\u662f\u5b50\u7ebf\u7a0b\uff0c\u5219\u5b50\u7ebf\u7a0b\u505c\u6b62\uff0c\u5176\u4ed6\u7ebf\u7a0b\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n
NoClassDefFoundError\u548cClassNotFoundException\u533a\u522b<\/p>\n
\u6211\u4eec\u7ecf\u5e38\u88abjava.lang.ClassNotFoundException\u548cjava.lang.NoClassDefFoundError\u8fd9\u4e24\u4e2a\u9519\u8bef\u8ff7\u60d1\u4e0d\u6e05\uff0c\u5c3d\u7ba1\u4ed6\u4eec\u90fd\u4e0eJava classpath\u6709\u5173\uff0c\u4f46\u662f\u4ed6\u4eec\u5b8c\u5168\u4e0d\u540c\u3002NoClassDefFoundError\u53d1\u751f\u5728JVM\u5728\u52a8\u6001\u8fd0\u884c\u65f6\uff0c\u6839\u636e\u4f60\u63d0\u4f9b\u7684\u7c7b\u540d\uff0c\u5728classpath\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u7c7b\u8fdb\u884c\u52a0\u8f7d\uff0c\u4f46\u5f53\u5b83\u627e\u4e0d\u5230\u8fd9\u4e2a\u7c7b\u65f6\uff0c\u5c31\u53d1\u751f\u4e86java.lang.NoClassDefFoundError\u7684\u9519\u8bef\uff0c\u800cClassNotFoundException\u662f\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u5728classpath\u4e2d\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u7c7b\u800c\u53d1\u751f\u7684\u9519\u8bef\u3002ClassNotFoundException\u6bd4NoClassDefFoundError\u5bb9\u6613\u89e3\u51b3\uff0c\u662f\u56e0\u4e3a\u5728\u7f16\u8bd1\u65f6\u6211\u4eec\u5c31\u77e5\u9053\u9519\u8bef\u53d1\u751f\uff0c\u5e76\u4e14\u5b8c\u5168\u662f\u7531\u4e8e\u73af\u5883\u7684\u95ee\u9898\u5bfc\u81f4\u3002\u800c\u5982\u679c\u4f60\u5728J2EE\u7684\u73af\u5883\u4e0b\u5de5\u4f5c\uff0c\u5e76\u4e14\u5f97\u5230NoClassDefFoundError\u7684\u5f02\u5e38\uff0c\u800c\u4e14\u5bf9\u5e94\u7684\u9519\u8bef\u7684\u7c7b\u662f\u786e\u5b9e\u5b58\u5728\u7684\uff0c\u8fd9\u8bf4\u660e\u8fd9\u4e2a\u7c7b\u5bf9\u4e8e\u7c7b\u52a0\u8f7d\u5668\u6765\u8bf4\uff0c\u53ef\u80fd\u662f\u4e0d\u53ef\u89c1\u7684\u3002<\/p>\n
\u600e\u4e48\u89e3\u51b3NoClassDefFoundError\u9519\u8bef<\/p>\n
\u6839\u636e\u524d\u6587\uff0c\u5f88\u660e\u663eNoClassDefFoundError\u7684\u9519\u8bef\u662f\u56e0\u4e3a\u5728\u8fd0\u884c\u65f6\u7c7b\u52a0\u8f7d\u5668\u5728classpath\u4e0b\u627e\u4e0d\u5230\u9700\u8981\u52a0\u8f7d\u7684\u7c7b\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u628a\u5bf9\u5e94\u7684\u7c7b\u52a0\u8f7d\u5230classpath\u4e2d\uff0c\u6216\u8005\u68c0\u67e5\u4e3a\u4ec0\u4e48\u7c7b\u5728classpath\u4e2d\u662f\u4e0d\u53ef\u7528\u7684\uff0c\u8fd9\u4e2a\u53d1\u751f\u53ef\u80fd\u7684\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n
\u5bf9\u5e94\u7684Class\u5728java\u7684classpath\u4e2d\u4e0d\u53ef\u7528<\/p>\n
\u4f60\u53ef\u80fd\u7528jar\u547d\u4ee4\u8fd0\u884c\u4f60\u7684\u7a0b\u5e8f\uff0c\u4f46\u7c7b\u5e76\u6ca1\u6709\u5728jar\u6587\u4ef6\u7684manifest\u6587\u4ef6\u4e2d\u7684classpath\u5c5e\u6027\u4e2d\u5b9a\u4e49<\/p>\n
\u53ef\u80fd\u7a0b\u5e8f\u7684\u542f\u52a8\u811a\u672c\u8986\u76d6\u4e86\u539f\u6765\u7684classpath\u73af\u5883\u53d8\u91cf<\/p>\n
\u56e0\u4e3aNoClassDefFoundError\u662fjava.lang.LinkageError\u7684\u4e00\u4e2a\u5b50\u7c7b\uff0c\u6240\u4ee5\u53ef\u80fd\u7531\u4e8e\u7a0b\u5e8f\u4f9d\u8d56\u7684\u539f\u751f\u7684\u7c7b\u5e93\u4e0d\u53ef\u7528\u800c\u5bfc\u81f4<\/p>\n
\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u4e2d\u662f\u5426\u6709java.lang.ExceptionInInitializerError\u8fd9\u6837\u7684\u9519\u8bef\uff0cNoClassDefFoundError\u6709\u53ef\u80fd\u662f\u7531\u4e8e\u9759\u6001\u521d\u59cb\u5316\u5931\u8d25\u5bfc\u81f4\u7684<\/p>\n
\u5982\u679c\u4f60\u5de5\u4f5c\u5728J2EE\u7684\u73af\u5883\uff0c\u6709\u591a\u4e2a\u4e0d\u540c\u7684\u7c7b\u52a0\u8f7d\u5668\uff0c\u4e5f\u53ef\u80fd\u5bfc\u81f4NoClassDefFoundError<\/p>\n
\u4e0b\u9762\u6211\u4eec\u770b\u4e00\u4e9b\u5f53\u53d1\u751fNoClassDefFoundError\u65f6\uff0c\u6211\u4eec\u8be5\u5982\u4f55\u89e3\u51b3\u7684\u6837\u4f8b\u3002<\/p>\n
NoClassDefFoundError\u89e3\u51b3\u793a\u4f8b<\/p>\n
\u5f53\u53d1\u751f\u7531\u4e8e\u7f3a\u5c11jar\u6587\u4ef6\uff0c\u6216\u8005jar\u6587\u4ef6\u6ca1\u6709\u6dfb\u52a0\u5230classpath\uff0c\u6216\u8005jar\u7684\u6587\u4ef6\u540d\u53d1\u751f\u53d8\u66f4\u4f1a\u5bfc\u81f4java.lang.NoClassDefFoundError\u7684\u9519\u8bef\u3002<\/p>\n
\u5f53\u7c7b\u4e0d\u5728classpath\u4e2d\u65f6\uff0c\u8fd9\u79cd\u60c5\u51b5\u5f88\u96be\u786e\u5207\u7684\u77e5\u9053\uff0c\u4f46\u5982\u679c\u5728\u7a0b\u5e8f\u4e2d\u6253\u5370\u51faSystem.getproperty(\u201cjava.classpath\u201d)\uff0c\u53ef\u4ee5\u5f97\u5230\u7a0b\u5e8f\u5b9e\u9645\u8fd0\u884c\u7684classpath<\/p>\n
\u8fd0\u884c\u65f6\u660e\u786e\u6307\u5b9a\u4f60\u8ba4\u4e3a\u7a0b\u5e8f\u80fd\u6b63\u5e38\u8fd0\u884c\u7684 -classpath \u53c2\u6570\uff0c\u5982\u679c\u589e\u52a0\u4e4b\u540e\u7a0b\u5e8f\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u8bf4\u660e\u539f\u6765\u7a0b\u5e8f\u7684classpath\u88ab\u5176\u4ed6\u4eba\u8986\u76d6\u4e86\u3002<\/p>\n
NoClassDefFoundError\u4e5f\u53ef\u80fd\u7531\u4e8e\u7c7b\u7684\u9759\u6001\u521d\u59cb\u5316\u6a21\u5757\u9519\u8bef\u5bfc\u81f4\uff0c\u5f53\u4f60\u7684\u7c7b\u6267\u884c\u4e00\u4e9b\u9759\u6001\u521d\u59cb\u5316\u6a21\u5757\u64cd\u4f5c\uff0c\u5982\u679c\u521d\u59cb\u5316\u6a21\u5757\u629b\u51fa\u5f02\u5e38\uff0c\u54ea\u4e9b\u4f9d\u8d56\u8fd9\u4e2a\u7c7b\u7684\u5176\u4ed6\u7c7b\u4f1a\u629b\u51faNoClassDefFoundError\u7684\u9519\u8bef\u3002\u5982\u679c\u4f60\u67e5\u770b\u7a0b\u5e8f\u65e5\u5fd7\uff0c\u4f1a\u53d1\u73b0\u4e00\u4e9bjava.lang.ExceptionInInitializerError\u7684\u9519\u8bef\u65e5\u5fd7\uff0cExceptionInInitializerError\u7684\u9519\u8bef\u4f1a\u5bfc\u81f4java.lang.NoClassDefFoundError: Could not initialize class\uff0c\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n
\/**<\/p>\n
* Java program to demonstrate how failure of static initialization subsequently cause<\/p>\n
* java.lang.NoClassDefFoundError in Java.<\/p>\n
*@author Javin Paul<\/p>\n
*\/<\/p>\n
public class NoClassDefFoundErrorDueToStaticInitFailure {
\n <\/p>\n
public static void main(String args[]){
\n <\/p>\n
Listusers = new ArrayList(2);<\/p>\n
for(int i=0; i<2; i++){
\n <\/p>\n
try{
\n <\/p>\n
users.add(new User(String.valueOf(i))); \/\/will throw NoClassDefFoundError<\/p>\n
}catch(Throwable t){
\n <\/p>\n
t.printStackTrace();<\/p>\n
}<\/p>\n
}<\/p>\n
}<\/p>\n
}<\/p>\n
class User{
\n <\/p>\n
private static String USER_ID = getUserId();<\/p>\n
public User(String id){
\n <\/p>\n
this.USER_ID = id;<\/p>\n
}<\/p>\n
private static String getUserId() {
\n <\/p>\n
throw new RuntimeException(\"UserId Not found\");<\/p>\n
}<\/p>\n
}<\/p>\n
Output<\/p>\n
java.lang.ExceptionInInitializerError<\/p>\n
at testing.NoClassDefFoundErrorDueToStaticInitFailure.main(NoClassDefFoundErrorDueToStaticInitFailure.java:23)<\/p>\n
Caused by: java.lang.RuntimeException: UserId Not found<\/p>\n
at testing.User.getUserId(NoClassDefFoundErrorDueToStaticInitFailure.java:41)<\/p>\n
at testing.User.(NoClassDefFoundErrorDueToStaticInitFailure.java:35)<\/p>\n
... 1 more<\/p>\n
java.lang.NoClassDefFoundError: Could not initialize class testing.User<\/p>\n
at testing.NoClassDefFoundErrorDueToStaticInitFailure.main(NoClassDefFoundErrorDueToStaticInitFailure.java:23)<\/p>\n
Read more: http:\/\/javarevisited.blogspot.com\/2011\/06\/noclassdeffounderror-exception-in.html#ixzz3dqtbvHDy<\/p>\n
1<\/p>\n
2<\/p>\n
3<\/p>\n
4<\/p>\n
5<\/p>\n
6<\/p>\n
7<\/p>\n
8<\/p>\n
9<\/p>\n
10<\/p>\n
11<\/p>\n
12<\/p>\n
13<\/p>\n
14<\/p>\n
15<\/p>\n
16<\/p>\n
17<\/p>\n
18<\/p>\n
19<\/p>\n
20<\/p>\n
21<\/p>\n
22<\/p>\n
23<\/p>\n
24<\/p>\n
25<\/p>\n
26<\/p>\n
27<\/p>\n
28<\/p>\n
29<\/p>\n
30<\/p>\n
31<\/p>\n
32<\/p>\n
33<\/p>\n
34<\/p>\n
35<\/p>\n
36<\/p>\n
37<\/p>\n
38<\/p>\n
39<\/p>\n
40<\/p>\n
41<\/p>\n
42<\/p>\n
43<\/p>\n
44<\/p>\n
\u7531\u4e8eNoClassDefFoundError\u662fLinkageError\u7684\u5b50\u7c7b\uff0c\u800cLinkageError\u7684\u9519\u8bef\u5728\u4f9d\u8d56\u5176\u4ed6\u7684\u7c7b\u65f6\u4f1a\u53d1\u751f\uff0c\u6240\u4ee5\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u4f9d\u8d56\u539f\u751f\u7684\u7c7b\u5e93\u548c\u9700\u8981\u7684dll\u4e0d\u5b58\u5728\u65f6\uff0c\u6709\u53ef\u80fd\u51fa\u73b0java.lang.NoClassDefFoundError\u3002\u8fd9\u79cd\u9519\u8bef\u4e5f\u53ef\u80fd\u629b\u51fajava.lang.UnsatisfiedLinkError: no dll in java.library.path Exception Java\u8fd9\u6837\u7684\u5f02\u5e38\u3002\u89e3\u51b3\u7684\u529e\u6cd5\u662f\u628a\u4f9d\u8d56\u7684\u7c7b\u5e93\u548cdll\u8ddf\u4f60\u7684jar\u5305\u653e\u5728\u4e00\u8d77\u3002<\/p>\n
\u5982\u679c\u4f60\u4f7f\u7528Ant\u6784\u5efa\u811a\u672c\u6765\u751f\u6210jar\u6587\u4ef6\u548cmanifest\u6587\u4ef6\uff0c\u8981\u786e\u4fddAnt\u811a\u672c\u83b7\u53d6\u7684\u662f\u6b63\u786e\u7684classpath\u503c\u5199\u5165\u5230manifest.mf\u6587\u4ef6<\/p>\n
Jar\u6587\u4ef6\u7684\u6743\u9650\u95ee\u9898\u4e5f\u53ef\u80fd\u5bfc\u81f4NoClassDefFoundError\uff0c\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u8fd0\u884c\u5728\u50cflinux\u8fd9\u6837\u591a\u7528\u6237\u7684\u64cd\u4f5c\u7cfb\u7edf\u79cd\uff0c\u4f60\u9700\u8981\u628a\u4f60\u5e94\u7528\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\uff0c\u5982Jar\u6587\u4ef6\uff0c\u7c7b\u5e93\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u7684\u6743\u9650\u5355\u72ec\u5206\u914d\u7ed9\u7a0b\u5e8f\u6240\u5c5e\u7528\u6237\u7ec4\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u4e86\u591a\u4e2a\u7528\u6237\u4e0d\u540c\u7a0b\u5e8f\u5171\u4eab\u7684jar\u5305\u65f6\uff0c\u5f88\u5bb9\u6613\u51fa\u73b0\u6743\u9650\u95ee\u9898\u3002\u6bd4\u5982\u5176\u4ed6\u7528\u6237\u5e94\u7528\u6240\u5c5e\u6743\u9650\u7684jar\u5305\u4f60\u7684\u7a0b\u5e8f\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\uff0c\u4f1a\u5bfc\u81f4java.lang.NoClassDefFoundError\u7684\u9519\u8bef\u3002<\/p>\n
\u57fa\u4e8eXML\u914d\u7f6e\u7684\u7a0b\u5e8f\u4e5f\u53ef\u80fd\u5bfc\u81f4NoClassDefFoundError\u7684\u9519\u8bef\u3002\u6bd4\u5982\u5927\u591a\u6570Java\u7684\u6846\u67b6\u50cfSpring\uff0cStruts\u4f7f\u7528xml\u914d\u7f6e\u83b7\u53d6\u5bf9\u5e94\u7684bean\u4fe1\u606f\uff0c\u5982\u679c\u4f60\u8f93\u5165\u4e86\u9519\u8bef\u7684\u540d\u79f0\uff0c\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u52a0\u8f7d\u5176\u4ed6\u9519\u8bef\u7684\u7c7b\u800c\u5bfc\u81f4NoClassDefFoundError\u5f02\u5e38\u3002\u6211\u4eec\u5728\u4f7f\u7528Spring MVC\u6846\u67b6\u6216\u8005Apache Struts\u6846\u67b6\uff0c\u5728\u90e8\u7f72War\u6587\u4ef6\u6216\u8005EAR\u6587\u4ef6\u65f6\u5c31\u7ecf\u5e38\u4f1a\u51fa\u73b0Exception in thread \u201cmain\u201d java.lang.NoClassDefFoundError\u3002<\/p>\n
\u5728\u6709\u591a\u4e2aClassLoader\u7684J2EE\u7684\u73af\u5883\u4e2d\uff0c\u5f88\u5bb9\u6613\u51fa\u73b0NoClassDefFoundError\u7684\u9519\u8bef\u3002\u7531\u4e8eJ2EE\u6ca1\u6709\u6307\u660e\u6807\u51c6\u7684\u7c7b\u52a0\u8f7d\u5668\uff0c\u4f7f\u7528\u7684\u7c7b\u52a0\u8f7d\u5668\u4f9d\u8d56\u4e0e\u4e0d\u540c\u7684\u5bb9\u5668\u50cfTomcat\u3001WebLogic\uff0cWebSphere\u52a0\u8f7dJ2EE\u7684\u4e0d\u540c\u7ec4\u4ef6\u5982War\u5305\u6216\u8005EJB-JAR\u5305\u3002\u5173\u4e8e\u7c7b\u52a0\u8f7d\u5668\u7684\u76f8\u5173\u77e5\u8bc6\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7\u6587\u7ae0\u7c7b\u52a0\u8f7d\u5668\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n
\u603b\u7ed3\u6765\u8bf4\uff0c\u7c7b\u52a0\u8f7d\u5668\u57fa\u4e8e\u4e09\u4e2a\u673a\u5236\uff1a\u59d4\u6258\u3001\u53ef\u89c1\u6027\u548c\u5355\u4e00\u6027\uff0c\u59d4\u6258\u673a\u5236\u662f\u6307\u5c06\u52a0\u8f7d\u4e00\u4e2a\u7c7b\u7684\u8bf7\u6c42\u4ea4\u7ed9\u7236\u7c7b\u52a0\u8f7d\u5668\uff0c\u5982\u679c\u8fd9\u4e2a\u7236\u7c7b\u52a0\u8f7d\u5668\u4e0d\u80fd\u591f\u627e\u5230\u6216\u8005\u52a0\u8f7d\u8fd9\u4e2a\u7c7b\uff0c\u90a3\u4e48\u518d\u52a0\u8f7d\u5b83\u3002\u53ef\u89c1\u6027\u7684\u539f\u7406\u662f\u5b50\u7c7b\u7684\u52a0\u8f7d\u5668\u53ef\u4ee5\u770b\u89c1\u6240\u6709\u7684\u7236\u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u7684\u7c7b\uff0c\u800c\u7236\u7c7b\u52a0\u8f7d\u5668\u770b\u4e0d\u5230\u5b50\u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u7684\u7c7b\u3002\u5355\u4e00\u6027\u539f\u7406\u662f\u6307\u4ec5\u52a0\u8f7d\u4e00\u4e2a\u7c7b\u4e00\u6b21\uff0c\u8fd9\u662f\u7531\u59d4\u6258\u673a\u5236\u786e\u4fdd\u5b50\u7c7b\u52a0\u8f7d\u5668\u4e0d\u4f1a\u518d\u6b21\u52a0\u8f7d\u7236\u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u8fc7\u7684\u7c7b\u3002\u73b0\u5728\u5047\u8bbe\u4e00\u4e2aUser\u7c7b\u5728WAR\u6587\u4ef6\u548cEJB-JAR\u6587\u4ef6\u90fd\u5b58\u5728\uff0c\u5e76\u4e14\u88abWAR ClassLoader\u52a0\u8f7d\uff0c\u800cWAR ClassLoader\u662f\u52a0\u8f7dEJB-JAR ClassLoader\u7684\u5b50ClassLoader\u3002\u5f53EJB-JAR\u4e2d\u4ee3\u7801\u5f15\u7528\u8fd9\u4e2aUser\u7c7b\u65f6\uff0c\u52a0\u8f7dEJB-JAR\u6240\u6709class\u7684Classloader\u627e\u4e0d\u5230\u8fd9\u4e2a\u7c7b\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u7c7b\u5df2\u7ecf\u88abEJB-JAR classloader\u7684\u5b50\u52a0\u8f7d\u5668WAR classloader\u52a0\u8f7d\u3002<\/p>\n
\u8fd9\u4f1a\u5bfc\u81f4\u7684\u7ed3\u679c\u5c31\u662f\u5bf9User\u7c7b\u51fa\u73b0NoClassDefFoundError\u5f02\u5e38\uff0c\u800c\u5982\u679c\u5728\u4e24\u4e2aJAR\u5305\u4e2d\u8fd9\u4e2aUser\u7c7b\u90fd\u5b58\u5728\uff0c\u5982\u679c\u4f60\u4f7f\u7528equals\u65b9\u6cd5\u6bd4\u8f83\u4e24\u4e2a\u7c7b\u7684\u5bf9\u8c61\u65f6\uff0c\u4f1a\u51fa\u73b0ClassCastException\u7684\u5f02\u5e38\uff0c\u56e0\u4e3a\u4e24\u4e2a\u4e0d\u540c\u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u7684\u7c7b\u65e0\u6cd5\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n
\u6709\u65f6\u5019\u4f1a\u51fa\u73b0Exception in thread \u201cmain\u201d java.lang.NoClassDefFoundError: com\/sun\/tools\/javac\/Main \u8fd9\u6837\u7684\u9519\u8bef\uff0c\u8fd9\u4e2a\u9519\u8bef\u8bf4\u660e\u4f60\u7684Classpath, PATH \u6216\u8005 JAVA_HOME\u6ca1\u6709\u5b89\u88c5\u914d\u7f6e\u6b63\u786e\u6216\u8005JDK\u7684\u5b89\u88c5\u4e0d\u6b63\u786e\u3002\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u529e\u6cd5\u65f6\u91cd\u65b0\u5b89\u88c5\u4f60\u7684JDK\u3002<\/p>\n
Java\u5728\u6267\u884clinking\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u4e5f\u53ef\u80fd\u5bfc\u81f4NoClassDefFoundError\u3002\u4f8b\u5982\u5728\u524d\u9762\u7684\u811a\u672c\u4e2d\uff0c\u5982\u679c\u5728\u7f16\u8bd1\u5b8c\u6210\u4e4b\u540e\uff0c\u6211\u4eec\u5220\u9664User\u7684\u7f16\u8bd1\u6587\u4ef6\uff0c\u518d\u8fd0\u884c\u7a0b\u5e8f\uff0c\u8fd9\u4e2a\u65f6\u5019\u4f60\u5c31\u4f1a\u76f4\u63a5\u5f97\u5230NoClassDefFoundError\uff0c\u800c\u9519\u8bef\u7684\u6d88\u606f\u53ea\u6253\u5370\u51faUser\u7c7b\u7684\u540d\u79f0\u3002<\/p>\n
java.lang.NoClassDefFoundError: testing\/User<\/p>\n
at testing.NoClassDefFoundErrorDueToStaticInitFailure.main(NoClassDefFoundErrorDueToStaticInitFailure.java:23)<\/p>\n
1<\/p>\n
2<\/p>\n
\u73b0\u5728\u6211\u4eec\u77e5\u9053\u8981\u600e\u6837\u53bb\u9762\u5bf9NoClassDefFoundError\u5f02\u5e38\u5e76\u89e3\u51b3\u5b83\u4e86\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"java.NoClassDefF_\u600e\u4e48\u89e3\u51b3java.lang.NoclassDeffFoundError\u9519\u8bef\u524d\u8a00\u5728\u65e5\u5e38Java\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u78b0\u5230java.lang.NoClassDefFou...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7196"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7196"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7196\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}