Member Avatar for charliesindex
charliesindex

I decided to develop a java applet to transfer files to a ftp server. I have no java experience but using stuff from the web and using NetBeans IDE for development, I came resonably close. Here is the code I used.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chalaka;
import org.apache.commons.net.ftp.FTPClient;
import java.io.FileInputStream;
import java.io.IOException;
import java.applet.Applet;

//public class NewApplet extends java.applet.Applet
public class FileUploadDemo extends Applet {

//public static void main(String[] args) {
public void init(){
    FTPClient client = new FTPClient();
    FileInputStream fis = null;
    try {
    client.connect("salpadoru.com");
    client.login("cataloguserftp", "NuranMehara01");
    //
    // Create an InputStream of the file to be uploaded
    //
    client.changeWorkingDirectory("c:/temp/");

    String filename = "Touch.dat";
    fis = new FileInputStream(filename);
    //
    // Store file to server
    //
    client.storeFile(filename, fis);
    client.logout();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    if (fis != null) {
    fis.close();
    }
    client.disconnect();
    } catch (IOException e) {
    e.printStackTrace();
}
}
}
}

This runs fine well run within the IDE but when I put this in a HTML, it gives following errors:

Java Plug-in 1.6.0_16
Using JRE version 1.6.0_16-b01 Java HotSpot(TM) Client VM
User home directory = C:\Users\chalaka

----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

Exception in thread "thread applet-chalaka/FileUploadDemo.class-1" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
    at chalaka.FileUploadDemo.init(FileUploadDemo.java:17)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClient
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 3 more
Caused by: java.io.FileNotFoundException: C:\Users\chalaka\Documents\NetBeansProjects\JavaApplication11\build\classes\org\apache\commons\net\ftp\FTPClient.class (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.[url]www.protocol.file.FileURLConnection.connect(Unknown[/url] Source)
    at sun.net.[url]www.protocol.file.FileURLConnection.getInputStream(Unknown[/url] Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more

Please help, thank you. see the HTML below:

<HTML>
<HEAD>
   <TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>

<!--
*** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***

If you need to modify this HTML launcher file (e.g., to add applet parameters), 
copy it to where your applet class is found in the SRC folder. If you do this, 
the IDE will use it when you run or debug the applet.

Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in 
the Packaging page in the Project Properties dialog.

For more information see the online help.
-->

<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

<P>
<APPLET codebase="classes" code="chalaka/FileUploadDemo.class" width=350 height=200></APPLET>
</P>

<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>