不能使用JavaScript code在Eclipse中的HTML显示小程序 [英] Can't display applet from html using javascript code in Eclipse

查看:285
本文介绍了不能使用JavaScript code在Eclipse中的HTML显示小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用Eclipse IDE中的JavaScript code运行Java小程序,如图网页的嵌入Java小程序到.html文件。但输出页面显示错误。我的code使用的小程序

 &LT;脚本的src =// www.java.com/js/deployJava.js\"></script>

在头部分和

 &LT;脚本&GT;
    VAR属性= {
        codeBase的:../src/',
        code:'transfol.Main.class',
        //存档:我-archive.jar',
        宽度:'800',
        高度:'500'
    };
    VAR参数= {
        java_arguments:-Xmx256m
    }; //按您的需求定制
    VAR的版本='1.5'; // JDK版本
    deployJava.runApplet(属性,参数,版本);
&LT; / SCRIPT&GT;

在主体部分

我救了他们的方式显示在导航器作为
包transfol这是在src文件夹(在Eclipse)和index.jsp的在网络里面的内容Main.class

其中Main.class是小程序和index.jsp的是从中小程序被调用的文件。

我几乎可以肯定,这个问题是在codeBase类或code属性所在的路径已被指定的,当我点击的小程序的更多信息,我得到异常为:


  

该folloing例外发生。欲了解更多信息,请尝试在命令行启动浏览器并检查输出。
  为了获得更大的信息,您可以访问 http://icedtea.classpath.org/wiki/IcedTea-Web < /没有描述如何获得必要的信息,提交错误一>,并按照步骤
  附加信息可以是在控制台或日志可用。如果启用了调试,甚至提供更多的信息。


另一个可用的信息:
的IcedTea-Web插件版本:1.5(1.5-1ubuntu1)
 26/5/15下午5点56
例外的是:

  net.sourceforge.jnlp.LaunchException:致命:初始化错误:无法初始化小程序。欲了解更多信息,请点击详细信息按钮。
    在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    在net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:908)
抛出java.lang.ClassNotFoundException:引起不能做一个codeBase的抬头,也没有罐子。如果不宜早不宜迟
    在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2个
这是发生启动您的小程序的例外列表中。请注意,这些例外可以从多个小程序产生。对于一个有用的bug报告,一定要只运行一个小程序。
1)26/5/15下午5:47
net.sourceforge.jnlp.LaunchException:致命:初始化错误:无法初始化小程序。欲了解更多信息,请点击详细信息按钮。
    在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:746)
    在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:675)
    在net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:908)
抛出java.lang.ClassNotFoundException:引起不能做一个codeBase的抬头,也没有罐子。如果不宜早不宜迟
    在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:716)
    ... 2个


解决方案

试试这个

Java小程序

\r
\r

包cdig;\r
\r
进口java.applet.Applet中;\r
进口java.security.AccessController;\r
进口java.security.PrivilegedAction;\r
\r
公共类CDigApplet扩展的Applet\r
{\r
\r
私有静态最后的serialVersionUID长1L =;\r
\r
串RET;\r
\r
CDigApplet小程序=这一点;\r
\r
@燮pressWarnings({rawtypes,未})\r
公共字符串signFile(FILEID字符串,字符串针,字符串标记)\r
{\r
在AccessController.doPrivileged(新的PrivilegedAction()\r
{\r
@覆盖\r
公共对象的run()\r
{\r
尝试\r
{\r
的System.out.println(Iniciando processo德assinatura。);\r
}\r
赶上(例外五)\r
{\r
字符串SL ={\\成功\\:假的,+\\消息\\:\\+ e.getMessage()+\\};\r
RET = SL;\r
的System.out.println(SL);\r
}\r
\r
返回null;\r
}\r
});\r
\r
返回RET;\r
}\r
\r
公共无效的init(){\r
}\r
\r
公共无效的destroy(){\r
}\r
\r
}

\r

\r
\r

HTML

\r
\r

&LT;脚本&GT;\r
    &所述;! - 小程序ID可用于到达该小程序对象的引用 - &GT;\r
    VAR属性= {ID:'cdigApplet',code:'cdig.CDigApplet',存档:cdig-applet的1.0.jar',宽度:1,身高:1,classloader_cache:'假'};\r
    VAR参数= {persistState:假的,cache_option:'不'};\r
    deployJava.runApplet(属性,参数,'1.8');\r
&LT; / SCRIPT&GT;

\r

\r
\r

通过JavaScript调用

\r
\r

VAR解析度=的document.getElementById(cdigApplet)。signFile(ID, '令牌);

\r

\r
\r

不要忘记签上你的小应用程序,并没有与URL用下划线像这样运行你的应用程序_。

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

解决方案

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.

这篇关于不能使用JavaScript code在Eclipse中的HTML显示小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆