を使用してブラウザで実行するJavaアプレットを取得:http://docs.oracle.com/javase/tutorial/deployment/applet/subclass.html私はここから取った非常に単純なJavaアプレットを持ってJNLP
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class HelloWorld extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
私は右クリックして[Run As > Java Applet
を行うときに日食で実行するアプレットを得ることができますが、今私はそれをjarファイルに入れようとしていて、ブラウザを通してjnlpを使って実行しようとしています。作成
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Hello Applet</title>
<vendor>Self</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="Hello.jar" main="true" />
</resources>
<applet-desc
name="Hello Applet"
main-class="HelloClass"
width="300"
height="300">
</applet-desc>
<update check="background"/>
</jnlp>
- :
javac -d build HelloClass.java
cd build
jar cvf Hello.jar *.class
- はHello.jnlpファイルを作成します。これらは、私はそれを試してみてやって撮影したの手順ですhtmlページ: 私は私のブラウザでこのページを開くと3210
<html> <head> <title>Hello Applet</title> </head> <body> <!-- ... --> <script src="http://www.java.com/js/deployJava.js"></script> <script> var attributes = { code:'HelloClass', width:300, height:300} ; var parameters = {jnlp_href: 'Hello.jnlp'} ; deployJava.runApplet(attributes, parameters, '1.6'); </script> <!-- ... --> </body> </html>
私は、アプレットの実行を許可するように求められますが、その後、私は、以下の詳細のようにエラーが出ます:
Exception: java.lang.UnsupportedClassVersionError: HelloClass : Unsupported major.minor version 51.0
それでした! 'javac -source 1.6 -target 1.6 -bootclasspath" C:¥Program Files¥Java¥jdk1.7.0_03¥jre¥lib¥rt.jar "-d Build HelloClass.java'このコマンドを使用してコードを再コンパイルできました。今は素晴らしい作品です。ここでリンクしているページの例を次に示します。[Crosscompile-example](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-example) – nates