I have a very simple java applet that I took from here: http://docs.oracle.com/javase/tutorial/deployment/applet/subclass.html
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");
}
}
}
I can get the applet to run in eclipse when I right click and do Run As > Java Applet
but now I'm trying to put it into a jar file and run it using jnlp through the browser. These are the steps I've taken to try and do that:
javac -d build HelloClass.java
cd build
jar cvf Hello.jar *.class
<?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>
<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>
When I open this page in my browser I get prompted to allow the applet to run but then I get a error with the following details:
Exception: java.lang.UnsupportedClassVersionError: HelloClass : Unsupported major.minor version 51.0
The code was apparently compiled by a 1.7 SDK without using any cross-compilation options, while the JRE that is trying to load it, is version 6 or less.
To compile code for a particular Java version, use the cross-compilation options. To do this properly will require an rt.jar
of the target version (to use the bootclasspath
option of javac
).