0

I've tried to run a java applet using the javascript code in Eclipse IDE as shown in the web page Embedding Java Applet into .html file. But the output page shows error. My code to use applet is

<script src="//www.java.com/js/deployJava.js"></script>

in the head section and

<script>
    var attributes = {
        codebase : '../src/',
        code : 'transfol.Main.class',
        //archive: 'my-archive.jar',
        width : '800',
        height : '500'
    };
    var parameters = {
        java_arguments : '-Xmx256m'
    }; // customize per your needs
    var version = '1.5'; // JDK version
    deployJava.runApplet(attributes, parameters, version);
</script>

in the body section.

The way I've saved them is shown in the Navigator as Main.class inside the package transfol which is in src folder (in Eclipse) and index.jsp in the web content

where Main.class is the applet and index.jsp is the file from which applet is being called.

I'm almost sure that the problem is in the codebase or code attributes where the path has to be specified, when I click on more information on applet, I get exception as:

The folloing exception has occured. For more information, try to launch the browser from the command line and examine the output. For even more information you can visit http://icedtea.classpath.org/wiki/IcedTea-Web and follow the steps described there on how to obtain necessary information to file bug Additional information may be available in the console or logs. Even more information is available if debugging is enabled.

Another available info: IcedTea-Web Plugin version: 1.5 (1.5-1ubuntu1) 26/5/15 5:56 PM Exception was:

net.sourceforge.jnlp.LaunchException: Fatal: Initialization Error: Could not initialize applet. For more information click "more information button".
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:908)
Caused by: java.lang.ClassNotFoundException: Can't do a codebase look up and there are no jars. Failing sooner rather than later
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2 more
This is the list of exceptions that occurred launching your applet. Please note, those exceptions can originate from multiple applets. For a helpful bug report, be sure to run only one applet. 
1) at 26/5/15 5:47 PM
net.sourceforge.jnlp.LaunchException: Fatal: Initialization Error: Could not initialize applet. For more information click "more information button".
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:908)
Caused by: java.lang.ClassNotFoundException: Can't do a codebase look up and there are no jars. Failing sooner rather than later
    at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2 more
Community
  • 1
  • 1
user41965
  • 111
  • 1
  • 7

2 Answers2

0

Try below code

 <APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
 </APPLET>

OR

 <object width="400" height="400" data="helloworld.class"></object> 
harsh
  • 97
  • 1
  • 7
  • Thanks for the reply, but it's not working. Result is the same just an error is being displayed on the applet space – user41965 May 26 '15 at 12:44
0

Try this

Java applet

package cdig;

import java.applet.Applet;
import java.security.AccessController;
import java.security.PrivilegedAction;

public class CDigApplet extends Applet
{

 private static final long serialVersionUID = 1L;

 String ret;

 CDigApplet applet = this;

 @SuppressWarnings({ "rawtypes", "unchecked" })
 public String signFile(String fileID, String pin, String token)
 {
  AccessController.doPrivileged(new PrivilegedAction()
  {
   @Override
   public Object run()
   {
    try
    {
     System.out.println("Iniciando processo de assinatura.");
    }
    catch (Exception e)
    {
     String sl = "{\"success\":false," + "\"message\":\"" + e.getMessage() + "\"}";
     ret = sl;
     System.out.println(sl);
    }

    return null;
   }
  });

  return ret;
 }

 public void init(){
 }

 public void destroy(){
 }

}

HTML

<script>
    <!-- applet id can be used to get a reference to the applet object -->
    var attributes = { id:'cdigApplet', code:'cdig.CDigApplet', archive:'cdig-applet-1.0.jar', width:1, height:1, classloader_cache:'false'} ;
    var parameters = {persistState: false, cache_option:'no' } ;
    deployJava.runApplet(attributes, parameters, '1.8');
</script>

Call via javascript

var res = document.getElementById("cdigApplet").signFile(Id, '', token);

Don't forget to sign your applet and to not run your app with a URL with underscores '_' like this.