![](/img/trans.png)
[英]Camel example can't find org.apache.camel.impl.DefaultComponent
[英]Apache Camel can't find servlet class
我想使用Apache Camel下載網頁,但不幸的是,我的努力因一堆可怕的錯誤而停止,這些錯誤似乎都是由以下原因引起的:
java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
我覺得這很混亂,因為它看起來像是標准庫中的類。
我在eclipse中創建了項目,並且在引用的庫中有:
應該完成這項工作的類代碼:
package camelexample;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class HttpDownload {
public static void main(String[] args) throws Exception{
System.out.print("download");
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder(){
public void configure(){
from("http://www.ii.uni.wroc.pl/~gst/").to("file:data/webpage.html");
}
});
context.start();
Thread.sleep(10);
context.stop();
}
}
為了運行項目,我只使用Eclipse的“運行”按鈕。 我究竟做錯了什么?
您需要使用Servlet API添加一個JAR,例如此JAR
org.apache.geronimo.specs:geronimo-servlet_2.5_spec:jar:1.1.2:compile
您可以在中央Maven回購中找到它: http : //repo2.maven.org/maven2/org/apache/geronimo/specs/geronimo-servlet_2.5_spec/1.1.2/
然后將該JAR添加到您的類路徑中。
而且由於您使用駱駝-http4(使用Apache Http Client 4.x),因此也需要其依賴項
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.1.3:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.1.4:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | \- commons-codec:commons-codec:jar:1.4:compile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.