The problem is pictured below:
A function of uploading files was developed on the previous project, using the class sun.net.ftp.FtpClient
The code to connect to the server is roughly as follows:
public static FtpClient ftpClient = null;
ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
Before this function was developed on the basis of jdk1.6 . Everything works fine.
However, because the customer's environment already has a jdk1.7 environment, it is directly deployed, and it is found that the file upload fails, and the following error is reported:
cannont instantiate the type FtpClient
After investigation, it was found
1) The sun.net.ftp.FtpClient class has no specific description in the jdk help document, that is, it is not exposed to the public. And this class is implemented in jdk's rt.jar.
2) Under jdk1.7, its constructor FtpClient() is defined as private type, so it cannot be new. In jdk1.7, it has been replaced by the FtpClient.create(ip) method
At the same time, some other methods have also been basically changed.
如 ftpClient.openServer(server);
ftpClient.login(user, password);
You can replace it with: ftpClient.login(user, null, password);
ftpClient.binary(); ---> ftpClient.setBinaryType();
ftpClient.put(remotefilename);--->ftpClient.putFileStream(remotefilename, true);
Wait.
If so, there are 2 ways to solve this problem:
1. Rewrite this upload function, but what about version 1.6, it may need to be processed separately according to the jdk version
2. On the existing server, build the 1.6 environment, and then load the 1.6 jdk when tomcat starts