使用URLClassLoader时的NoClassDefFoundError

时间:2015-05-04 10:58:51

标签: java noclassdeffounderror urlclassloader

我正在尝试创建一个插件存储,我的java代码在运行时动态下载存储中的现有jar。我实现了一个应该由每个插件实现的接口。 这是我使用的代码,

 Manifest-Version: 1.0
Class-Path: . VideoPlugin_lib/apache-mime4j-0.6.jar VideoPlugin_lib/bs
 h-1.3.0.jar VideoPlugin_lib/cglib-nodep-2.1_3.jar VideoPlugin_lib/com
 mons-codec-1.9.jar VideoPlugin_lib/commons-collections-3.2.1.jar Vide
 oPlugin_lib/commons-exec-1.1.jar VideoPlugin_lib/commons-io-2.4.jar V
 ideoPlugin_lib/commons-jxpath-1.3.jar VideoPlugin_lib/commons-lang3-3
 .3.2.jar VideoPlugin_lib/commons-logging-1.1.3.jar VideoPlugin_lib/cs
  sparser-0.9.14.jar VideoPlugin_lib/gson-2.3.1.jar VideoPlugin_lib/gua
  va-18.0.jar VideoPlugin_lib/hamcrest-core-1.3.jar VideoPlugin_lib/ham
   crest-library-1.3.jar VideoPlugin_lib/htmlunit-2.15.jar VideoPlugin_l
   ib/htmlunit-core-js-2.15.jar VideoPlugin_lib/httpclient-4.3.6.jar Vid
   eoPlugin_lib/httpcore-4.3.3.jar VideoPlugin_lib/httpmime-4.3.6.jar Vi
   deoPlugin_lib/ini4j-0.5.2.jar VideoPlugin_lib/jcommander-1.29.jar Vid
    eoPlugin_lib/jetty-websocket-8.1.8.jar VideoPlugin_lib/jna-3.4.0.jar 
    VideoPlugin_lib/jna-platform-3.4.0.jar VideoPlugin_lib/json-simple-1.
    1.1.jar VideoPlugin_lib/junit-dep-4.11.jar VideoPlugin_lib/nekohtml-1
   .9.21.jar VideoPlugin_lib/netty-3.5.7.Final.jar VideoPlugin_lib/opera
   driver-1.5.jar VideoPlugin_lib/phantomjsdriver-1.2.1.jar VideoPlugin_
   lib/protobuf-java-2.4.1.jar VideoPlugin_lib/sac-1.3.jar VideoPlugin_l
   ib/selenium-java-2.45.0-srcs.jar VideoPlugin_lib/selenium-java-2.45.0
   .jar VideoPlugin_lib/serializer-2.7.1.jar VideoPlugin_lib/testng-6.8.
    5.jar VideoPlugin_lib/xalan-2.7.1.jar VideoPlugin_lib/xercesImpl-2.11
    .0.jar VideoPlugin_lib/xml-apis-1.4.01.jar 

这是视频插件的清单

 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/protocol/HttpCoreContext
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.gargoylesoftware.htmlunit.HttpWebConnection.<init>(HttpWebConnection.java:147)
at com.gargoylesoftware.htmlunit.WebClient.createWebConnection(WebClient.java:1907)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:134)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:303)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:277)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:148)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:195)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:191)
at selenium.Search.search(Search.java:17)
at selenium.Search.sendLinks(Search.java:101)
at selenium.VideoPlugin.getSize(VideoPlugin.java:163)
at MobileCloud.Test.main(Test.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.http.protocol.HttpCoreContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 25 more

当我尝试运行此代码时,它给了我这个例外:

Update <table-name> SET <column-name> = ROUND(<column-name>, 2);

PS:这个代码适用于其他jar,即使外部库也很好,这个jar在终端上运行良好。

2 个答案:

答案 0 :(得分:1)

org.apache.http.protocol.HttpCoreContext不在httpcore 4.3.3 jar中。

可能是你使用了错误的Jar版本,或者你的做法是错误的。

答案 1 :(得分:0)

当我查看这个插件使用的库时,问题解决了,我发现我使用的是类似的库但是旧的版本,所以我从类路径中删除了我的库,程序正常运行