Thanks . The problem is solved !! 2014-12-04 13:43 GMT+08:00 Zhou, Richard <[email protected]>:
> Since the tar.gz is blocked by security, I will attached the file > separately. > > > > *From:* Zhou, Richard [mailto:[email protected]] > *Sent:* Thursday, December 04, 2014 1:26 PM > *To:* [email protected]; 呂佳鴻 > *Subject:* RE: sqoop 1.99.3 problem in using java api > > > > Hi, > > > > I have tested it. And it works fine. The source code of > the project is attached. > > Run command “mvn clean compile assembly:single” to build > jar with dependency, in case there is no maven repo in your test > environment. > > Run command “java -classpath > test-1.0-SNAPSHOT-jar-with-dependencies.jar com.intel.richard.App” with > your jar package “test-1.0-SNAPSHOT-jar-with-dependencies.jar”. > > And here is the result from Sqoop client: > > > ============================================================================== > > [root@server-519 richard]# sh /usr/lib/sqoop2/bin/sqoop.sh client > > Sqoop home directory: /usr/lib/sqoop2 > > > :/usr/lib/sqoop2/client-lib/commons-cli-1.2.jar:/usr/lib/sqoop2/client-lib/commons-lang-2.6.jar:/usr/lib/sqoop2/client-lib/groovy-all-1.8.5.jar:/usr/lib/sqoop2/client-lib/hamcrest-core-1.3.jar:/usr/lib/sqoop2/client-lib/jansi-1.7.jar:/usr/lib/sqoop2/client-lib/jersey-client-1.11.jar:/usr/lib/sqoop2/client-lib/jersey-core-1.9.jar:/usr/lib/sqoop2/client-lib/jline-0.9.94.jar:/usr/lib/sqoop2/client-lib/json-simple-1.1.jar:/usr/lib/sqoop2/client-lib/log4j-1.2.16.jar:/usr/lib/sqoop2/client-lib/sqoop-client-1.99.3-cdh5.2.0.jar:/usr/lib/sqoop2/client-lib/sqoop-common-1.99.3-cdh5.2.0.jar:/usr/lib/sqoop2/client-lib/sqoop-shell-1.99.3-cdh5.2.0.jar > > Sqoop Shell: Type 'help' or '\h' for help. > > > > sqoop:000> show connection > > +----+--------------+-----------+---------+ > > | Id | Name | Connector | Enabled | > > +----+--------------+-----------+---------+ > > | 1 | c | 1 | true | > > | 2 | MyConnection | 1 | true | > > +----+--------------+-----------+---------+ > > > ============================================================================== > > > > > > Btw, I use 1.99.3 sqoop-shell lib in pom.xml. > > > > <dependency> > > <groupId>org.apache.sqoop</groupId> > > <artifactId>sqoop-shell</artifactId> > > <version>1.99.3</version> > > </dependency> > > > > Regards > > Richard > > > > *From:* Abraham Elmahrek [mailto:[email protected] <[email protected]>] > *Sent:* Thursday, December 04, 2014 12:11 PM > *To:* [email protected] > *Subject:* Re: sqoop 1.99.3 problem in using java api > > > > Hey there, > > > > What are you trying to achieve exactly? It seems like you are extending > Sqoop2 instead of using its Java client? > > > > -Abe > > > > On Wed, Dec 3, 2014 at 1:04 AM, 呂佳鴻 <[email protected]> wrote: > > hi , i have problem in using sqoop java api. > > First, I add dependency to sqoop (sqoop/shell/pom.xml) > > and run command: mvn install > > (Is it correct ?) > > > > Here is the testing code i use > > > > import org.apache.sqoop.client.SqoopClient; > > import org.apache.sqoop.model.MConnection; > > import org.apache.sqoop.model.MConnectionForms; > > import org.apache.sqoop.model.MJob; > > import org.apache.sqoop.model.MJobForms; > > import org.apache.sqoop.model.MSubmission; > > import org.apache.sqoop.submission.counter.Counter; > > import org.apache.sqoop.submission.counter.CounterGroup; > > import org.apache.sqoop.submission.counter.Counters; > > import org.apache.sqoop.validation.Status; > > import org.apache.sqoop.*; > > public class SqoopAccess{ > > public static void main(String[] args){ > > String url = "http://localhost:12000/sqoop/"; > > SqoopClient client = new SqoopClient(url); > > client.setServerUrl(url); > > MConnection newCon = client.newConnection(1); > > > > MConnectionForms conForms = newCon.getConnectorPart(); > > MConnectionForms frameworkForms = newCon.getFrameworkPart(); > > newCon.setName("MyConnection"); > > > conForms.getStringInput("connection.connectionString").setValue("jdbc:mysql://localhost/sqoop_test"); > > > conForms.getStringInput("connection.jdbcDriver").setValue("com.mysql.jdbc.Driver"); > > conForms.getStringInput("connection.username").setValue("root"); > > conForms.getStringInput("connection.password").setValue("root"); > > frameworkForms.getIntegerInput("security.maxConnections").setValue(0); > > } > > } > > > > > > when i run, i got the exception > > > > Exception in thread "main" java.lang.NoClassDefFoundError: > org/apache/sqoop/common/ErrorCode > > at SqoopAccess.main(SqoopAccess.java:15) > > Caused by: java.lang.ClassNotFoundException: > org.apache.sqoop.common.ErrorCode > > at java.net.URLClassLoader$1.run(URLClassLoader.java:372) > > at java.net.URLClassLoader$1.run(URLClassLoader.java:361) > > at java.security.AccessController.doPrivileged(Native Method) > > at java.net.URLClassLoader.findClass(URLClassLoader.java:360) > > at java.lang.ClassLoader.loadClass(ClassLoader.java:424) > > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) > > at java.lang.ClassLoader.loadClass(ClassLoader.java:357) > > ... 1 more > > > > Which part is incorrect? > > I'm no idea for how to use it . > > Is any sample i can find or use on the website? > > Thanks. > > >
