操作系统:Mac OS X 10.7.3 Chrome:19.0.1051.0金丝雀 Java:Java SE 6的32位和64位版本
目录结构:
page.html中:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing applet</title>
<style type="text/css">
</style>
<script type="application/javascript">
</script>
</head>
<body>
<object type="application/x-java-applet" height="300" width="550">
<param name="code" value="com.tyilo.Test.Test">
<param name="archive" value="Test.jar">
Applet failed to run. No Java plug-in was found.
</object>
</body>
</html>
Test.java:
package com.tyilo.Test;
import java.awt.Graphics;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.security.AccessControlException;
import javax.swing.JApplet;
public class Test extends JApplet
{
private static final long serialVersionUID = 1L;
public String text;
@Override
public void init()
{
text = "~/test.txt created successfully!";
try
{
FileWriter fstream = new FileWriter(System.getProperty("user.home") + "/test.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Testing123");
out.close();
}
catch(AccessControlException e)
{
text = "File permission error.";
}
catch(Exception e)
{
text = "Unknown error: " + e.getMessage();
}
}
@Override
public void paint(Graphics g)
{
g.drawString(text, 50, 30);
}
@Override
public void start()
{
//TODO
}
@Override
public void stop()
{
//TODO
}
@Override
public void destroy()
{
//TODO
}
}
chrome中的Java控制台错误:
load: class com.tyilo.Test.Test not found.
java.lang.ClassNotFoundException: com.tyilo.Test.Test
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:690)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.ClassNotFoundException: com.tyilo.Test.Test
修改 代码似乎在最新的稳定版本的chrome中运行良好,所以这可能只是金丝雀版本中的错误。
修改2
在本地运行html(和jar)时,chrome只有一个问题。
答案 0 :(得分:1)
我建议使用deployjava.js http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html
安东尼
答案 1 :(得分:0)
在chrome中启用java,为此,键入javascript:if(browser.value.getIndex(“chrome”){chrome.browser.enableFeature(JApplet)}); in to chrome