我们正在尝试使用Java进行Sqoop导入,在我尝试从ImportTool删除不推荐使用的com.cloudera.sqoop.SqoopOptions之前,它可以正常工作,如下面的代码片段所示。apache.sqoop.SqoopOptions可以替代包cloudera.sqoop.SqoopOptions,但ImportTool只支持cloudera包,已弃用。编写此代码的另一种方式是什么?请帮忙。
import org.apache.sqoop.tool.ImportTool;
import org.apache.sqoop.SqoopOptions;
import org.apache.sqoop.SqoopOptions.InvalidOptionsException;
//import com.cloudera.sqoop.SqoopOptions;
//import com.cloudera.sqoop.SqoopOptions.InvalidOptionsException;
public int sqoopImport(String name) throws ThrowIt {
try {
ImportTool importTool = new ImportTool();
SqoopOptions sqoopOptions = importTool.parseArguments(arg.toArray(new String[0]), configuration, null,
true);
importTool.validateOptions(sqoopOptions); //Error here, ImportTool needs sqoopOption from cloudera which is deprecated.
returnValue = importTool.run(sqoopOptions); //Error here, ImportTool needs sqoopOption from cloudera which is deprecated.
}
下载此jar:-enter link description here
公共类TestSSH {
public static void main(String args [])引发异常{
// Initialize a ConnBean object, the parameter list is IP, username, password
ConnBean cb = new ConnBean("192.168.56.102", "root","hadoop");
// Put the ConnBean instance as parameter for SSHExec static method getInstance(ConnBean) to retrieve a singleton SSHExec instance
SSHExec ssh = SSHExec.getInstance(cb);
// Connect to server
ssh.connect();
CustomTask sampleTask1 = new ExecCommand("echo $SSH_CLIENT"); // Print Your Client IP By which you connected to ssh server on Horton Sandbox
System.out.println(ssh.exec(sampleTask1));
CustomTask sampleTask2 = new ExecCommand("sqoop import --connect jdbc:mysql://192.168.56.101:3316/mysql_db_name --username=mysql_user --password=mysql_pwd --table mysql_table_name --hive-import -m 1 -- --schema default");
ssh.exec(sampleTask2);
ssh.disconnect();
}}