Java Reference
In-Depth Information
Note that no main class has been specified in the JNLP file. It is declared in the manifest file
into the file
test.jar
; otherwise, the launch process would fail.
Listing 8.2 supplies the
Test
class. It pops up a little dialog box, informing the user that the
application was successfully launched, and exits after 10 seconds.
L
ISTING
8.2
The Test Java Class
import javax.swing.*;
public class Test {
public Test() throws Exception {
JDialog jd = new JDialog();
jd.setSize(200,100);
jd.setLocation(100,100);
jd.setTitle(“Hello JNLP!”);
jd.getContentPane().add(new JLabel(“Launching Test Successful.”));
jd.setVisible(true);
Thread.currentThread().sleep(10000);
System.exit(0);
}
public static void main(String[] args) throws Exception {
Test test1 = new Test();
8
}
}
The remainder of this subsection is intended for novice programmers. Please feel free to skip it
to proceed to the execution subsection.
You can use the included
run.bat
script for Windows machines if you prefer to compile the
Test
class on your computer.
Then, prepare the JAR file with the following command:
jar cvfm test.jar manifest.txt *.class
You need the compiled
Test.class
file and the
manifest.txt
file shown in Listing 8.3.
L
ISTING
8.3
The Manifest File for the Test.jar File
Manifest-Version: 1.0
Main-Class: Test