08B Deployment Options
08B Deployment Options
Deploying Java
Applications
Originals of Slides and Source Code for Examples:
http://courses.coreservlets.com/Course-Materials/java.html
• Advantages
– Very simple to set up
– Programmers can modify individual classes easily
• Disadvantages
– Requires lots of separate files
• Painful to install
– Messy for non-Java-programmers
– Requires the right Java version
– No option for updates of class files
– No option to assist in installing Java
7
Individual Class Files: Example
public class Phisher extends JFrame {
public Phisher(String company) {
WindowUtilities.setNativeLookAndFeel();
addWindowListener(new ExitListener());
Container content = getContentPane();
String title = company + " Security Verification";
setTitle(title);
String imageURL =
"http://images.encarta.msn.com/xrefmedia/" +
"sharemed/targets/images/pho/000a5/000a5038.jpg";
String labelText =
"<html><CENTER><H1>" + title + "</H1>" +
"<IMG SRC=" + imageURL + "><BR>" +
"<H2>Your " + company + " account may have been " +
"compromised.<BR>To avoid cancellation, please " +
"reenter your account information.<BR>Sorry for " +
"the inconvenience, but security is our " +
"priority.</H2>";
8 JLabel label = new JLabel(labelText); ...
9
JAR Files: Approach
• Create a text file that designates main class
– Main-Class: classname
10
11
JAR Files: Example
• ManifestEntry.txt
Main-Class: Launcher
Blank line here!
12
OS Wrapper
• Wrap the call to Java inside a .bat file (Windows) or
shell script (Unix/Linux)
– User can execute it in normal way (e.g., double click it)
– Use javaw instead of java to avoid a popup console
• Advantages
– User does not need to open DOS window or Unix shell
– Double clicking icon is more natural to most users
• Disadvantages
– File must be in same directory as .class files or JAR file
• Or contain full path to class/JAR files
– Requires the right Java version
– No option for updates of class files
– No option to assist in installing Java
• Launcher.bat
13 javaw –jar Launcher.jar
Applets: Approach
• Create a Web page that refers to an applet
<APPLET CLASS="MyApplet.class" ...>
Warning for users without Java
</APPLET>
– There is also Java plugin alternative with extra options
– Applets covered in earlier lecture
• User loads URL in browser
– http://host/path/filewithapplet.html
• Applets can be embedded within browser or
launch separate popup windows
14
Applets: Pros/Cons
• Advantages
– User can bookmark location
– User gets updates automatically
• Disadvantages
– Security restrictions
• Applets cannot read/write local files, execute local
programs, open arbitrary network connections, etc.
• Digitally signed applets partially mitigate this
– User must have right version of Java plugin
– Accessed through browser
• Does not seem like a "regular" program
15
Applets: Example
• Yahoo Games (http://games.yahoo.com/)
16
17
Java WebStart: Pros/Cons
• Advantages
– Ensures user has latest application updates
• Downloads automatically
– Ensures user has proper Java version
• Downloads with minimal user intervention
– JAR files cached locally
• Faster download, offline execution
– Can create desktop shortcut as launcher
• Disadvantages
– Similar security restrictions to applets
• Again, digital signatures can mitigate this
– User must have some WebStart version installed
• Fails for users that do not have Java installed at all
• Autodetection of WebStart requires JavaScript code
18
19
Java WebStart: Example
(GUI Code)
public class Phisher2 extends JFrame {
public Phisher2(String company) {
WindowUtilities.setNativeLookAndFeel();
addWindowListener(new ExitListener());
Container content = getContentPane();
String title = company + " Security Verification";
setTitle(title);
String labelText =
"<html><CENTER><H1>" + title + "</H1>" +
"<H2>Your " + company + " account may have been " +
"compromised.<BR>To avoid cancellation, please " +
"reenter your account information.<BR>Sorry for " +
"the inconvenience, but security is our " +
"priority.</H2>";
JLabel label = new JLabel(labelText);
ClassLoader cl = getClass().getClassLoader();
Icon bankVaultIcon =
new ImageIcon(cl.getResource("images/bankvault.jpg"));
20 label.setIcon(bankVaultIcon);
21
Java WebStart: Example
(JNLP File)
<jnlp spec="1.0"
codebase="http://www.coreservlets.com/webstartdemo"
href="Phisher2.jnlp">
<information>
<title>Phisher2</title>
<vendor>freesecuritywarnings.com</vendor>
<offline-allowed/>
</information>
<resources>
<j2se version="1.5+"
href="http://java.sun.com/products/autodl/j2se"/>
<jar href="Phisher2.jar"/>
</resources>
<application-desc main-class="Launcher2"/>
</jnlp>
22
23
Java WebStart: Other JNLP File
Capabilities
• Bypassing security
– <security><all-permissions/></security>
– Asks user for permission to run in unrestricted mode
• Requires your JAR file(s) to be digitally signed
• Auto-Shortcut
– <shortcut online="false">
<desktop/>
<menu submenu="My Corporation Apps"/>
</shortcut>
• java-vm-args (attribute of j2se element)
– Lets you pass args to java
• More JNLP syntax info
– http://java.sun.com/j2se/1.5.0/docs/guide/javaws/
developersguide/syntax.html
24
Summary
• Individual class files
– Pros: simple to set up, easy Java programmer to edit
– Cons: no auto-updates of code or Java version, nonintuitive to non-
programmer
• JAR files
– Pros: single file
– Cons: same as class files
• OS wrapper
– Pros: more intuitive (clickable)
– Cons: same as class files
• Applets
– Pros: Web access, auto-updates of code, security
– Cons: Web only, no auto-update of Java version, security
• Java WebStart
– Pros: Web/desktop access, auto-updates of code and Java, security
– Cons: more complicated, security
27
© 2012 Marty Hall
Questions?
JSF 2, PrimeFaces, Java 7, Ajax, jQuery, Hadoop, RESTful Web Services, Android, Spring, Hibernate, Servlets, JSP, GWT, and other Java EE training.