Hi Folks,
I want to pass data to stream through the "stream client".
Here is my code:
————————————————————————————————————
package com.hackspark.rtt;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.apache.commons.io.Charsets;
import co.cask.cdap.client.StreamClient;
import co.cask.cdap.client.StreamWriter;
import co.cask.cdap.client.rest.RestStreamClient;
public class StreamCtrl{
public static void main(String... args) throws IOException{
StreamClient streamClient = new RestStreamClient.Builder("localhost",10000).build();
streamClient.create("gps");
StreamWriter streamWriter= streamClient.createWriter("gps");
File file = null;
try{
file = new File("/Documents/map.txt");
}catch(NullPointerException e){
//ignore
}
BufferedReader reader = null;
String line = null;
try{
reader = new BufferedReader(new FileReader(file));
while( (line = reader.readLine()) != null ){
streamWriter.write(line,Charsets.UTF_8);
}
}catch (IOException e){
e.printStackTrace();
}catch (NullPointerException ee){
ee.printStackTrace();
}finally{
reader.close();
}
}
}
——————————————————————————————————————————
And I can successfully "mvn clean package" and then generate the .jar document.After this , I set the main-class enter point.
But,I encoutered this error:
——————————————————————————————————————————
java -jar streamclient-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: co/cask/cdap/client/StreamClient
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: co.cask.cdap.client.StreamClient
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)
... 6 more
————————————————————————————————————————————
The solutions I had tried:
1.inspect the MANIFEST.MF :
there are these entries:
--Embed-Directory: lib
--Embedded-Artifacts: there has "lib/cdap-stream-client-1.0.1.jar" in this entry.
--Bundle-ClassPath:there has "lib/cdap-stream-client-1.0.1.jar" in this entry
--Main-Class:
and so on.
IS there something wrong above?
And I add this to the classpath , BUT there is a new error:
————————————————————————————————————————————————————
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
at co.cask.cdap.client.rest.RestStreamClient$Builder.build(RestStreamClient.java:224)
at cn.siat.hackspark.StreamCtrl.main(StreamCtrl.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.HttpClientConnectionManager
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)
... 2 more
————————————————————————————————————————————
It seems like the dependency is not right. Am i right?
How can i figure out the solution?
Cheers,
-Young