我正在开发一个Java实用程序,它将文件从HDFS获取到远程计算机。我在SFTP库导入中遇到了一些问题。我在POM中包含了org mule传输和相关库,在进行mvn安装后,我可以看到类在依赖路径中可用。但是,当我执行该类时,我收到如下错误消息:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mule/transport/sftp/SftpClient
at xxxx.yyyyyy.sftpFileTransfer.main(sftpFileTransfer.java:17)
Caused by: java.lang.ClassNotFoundException: org.mule.transport.sftp.SftpClient
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)
... 1 more
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.mule.transport.sftp.SftpClient;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelSftp.LsEntry;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.mule.transport.sftp.SftpClient;
public class sftpFileTransfer {
public static void main(String[] args) throws IOException {
System.out.println("This is for testing");
SftpClient sftpCli = new SftpClient("abcdef");
sftpCli.login("karthick_kb","/home/karthick/.ssh/id_rsa", null);
sftpCli.changeWorkingDirectory("/tmp/");
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
FSDataInputStream fsdisPath = null;
String filePath = null;
filePath = "/a/b/c/d/e/f/1.dat.gz";
Path inputPath = new Path(filePath);
fsdisPath = fs.open(inputPath);
BufferedInputStream bis = new BufferedInputStream(fsdisPath);
sftpCli.storeFile(inputPath.getName(), bis);
fsdisPath.close();
}
}
maven依赖关系如下
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>org.mule</groupId>
<artifactId>mule-core</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-sftp</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
我能够在maven依赖项中看到所需的SFTP类我可能会遗漏什么......任何信息都会很棒