无法在ubuntu服务器中执行jar文件

izkcnapc  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(356)

我有一个小的sqoop导入项目,我必须从mysql导入到hdfs。这是一个maven项目,当我在本地系统中运行时,它运行得很好。现在,当我试图在我的ubuntu服务器上运行jar文件时,它正在执行,但没有显示任何输出。它不是一个基于web的应用程序,我运行hadoop deamons并运行这个项目的普通应用程序。告诉我如何在服务器上运行这种类型的项目并运行。

package org.ezytruk.sqoop;

import java.io.FileInputStream;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.sqoop.tool.ImportTool;

import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.SqoopOptions.FileLayout;

public class SqoopImport {
    public static void importMySQLToHDFS() throws Exception {
        try {
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver).newInstance();

            Configuration config = new Configuration();
            config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/core-site.xml"));
            config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/hdfs-site.xml"));

            Properties properties = new Properties();
            properties.load(new FileInputStream("/home/*****/SqoopImportHDFS/resources/sqoopImport.properties"));

            //org.apache.sqoop.SqoopOptions sqoopOptions = new org.apache.sqoop.SqoopOptions();
            SqoopOptions sqoopOptions = new SqoopOptions();
            sqoopOptions.setDriverClassName(driver);
            sqoopOptions.setHadoopHome("/usr/local/hadoop");
            sqoopOptions.setConnectString(properties.getProperty("db_mysql_connection_string"));
            sqoopOptions.setTableName(properties.getProperty("db_mysql_table_name"));
            sqoopOptions.setUsername(properties.getProperty("db_mysql_username"));
            sqoopOptions.setPassword(properties.getProperty("db_mysql_password"));
            sqoopOptions.setNumMappers(1);
            //sqoopOptions.setWarehouseDir(properties.getProperty("db_hdfs_warehouse_directory"));
            sqoopOptions.setTargetDir(properties.getProperty("db_hdfs_output_directory"));
            sqoopOptions.setFileLayout(FileLayout.TextFile);
            new ImportTool().run(sqoopOptions);

            } catch (Exception e) {

         }

     }
       public static void main(String[] args) throws Exception {

        SqoopImport mySqlImport = new SqoopImport();
        mySqlImport.importMySQLToHDFS();

    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题