Upload
valerie-williams
View
219
Download
0
Embed Size (px)
Citation preview
Deployment via jars and Deployment via jars and WebstartWebstart
How do we distribute our How do we distribute our application?application?
Lab says you need to submit CDLab says you need to submit CD Limitations of CDLimitations of CD
fixed sizefixed size classes are fixedclasses are fixed java vm requirement fixedjava vm requirement fixed Granny can't run it in DesMoineGranny can't run it in DesMoine Maybe Granny likes to save money and Maybe Granny likes to save money and
use the library computeruse the library computer
(JAR) Java ARchive files (JAR) Java ARchive files
based on pkzip (rename from boo.jar to based on pkzip (rename from boo.jar to boo.zip and it becomes a zip file)boo.zip and it becomes a zip file)
holds:holds: class filesclass files information about the contained filesinformation about the contained files can hold other stuff, like gifs!can hold other stuff, like gifs!
Best of allBest of all can be made executablecan be made executable application runs out of the jar fileapplication runs out of the jar file don't have to unjar (unpack) itdon't have to unjar (unpack) it
Example: SimpleGui.jarExample: SimpleGui.jar
I have a project, called GiftI have a project, called Gift c:\Gift is the directoryc:\Gift is the directory
I have a package, called cs201I have a package, called cs201 c:\Gift\cs201 is the directory containing:c:\Gift\cs201 is the directory containing:
SimpleGUI.javaSimpleGUI.java SimpleGUI.classSimpleGUI.class Olsson001.gifOlsson001.gif
Jar options (complete list at Jar options (complete list at end of slides)end of slides)
jar –cf SimpleGUI.jar cs201jar –cf SimpleGUI.jar cs201 createcreate
jar –xf SimpleGUI.jar jar –xf SimpleGUI.jar extractextract
jar –tf SimpleGUI.jar jar –tf SimpleGUI.jar list contentslist contents
Make it executableMake it executable
See slides at endSee slides at end need to include a file (manifest) that need to include a file (manifest) that
tells java where the main() method istells java where the main() method is jar –cvmf manifest.txt SimpleGUI.jar jar –cvmf manifest.txt SimpleGUI.jar
cs201cs201 m in –cvmf means, include the manifest file m in –cvmf means, include the manifest file
(manifest.txt) in the jar(manifest.txt) in the jar
How to run the jar fileHow to run the jar file
double-click itdouble-click it oror java –jar SimpleGUI.jarjava –jar SimpleGUI.jar
TrustTrust
Java security based on the SandboxJava security based on the Sandbox we'll let you have limited access to we'll let you have limited access to
system resourcessystem resources you cannot read or write to local diskyou cannot read or write to local disk you (usually) only read from the website you (usually) only read from the website
from which you are downloadedfrom which you are downloaded can't attack other sites, e.g.can't attack other sites, e.g.
Increased securityIncreased security
Signing a jar fileSigning a jar file signifies who created itsignifies who created it somewhat informalsomewhat informal you can spend $$ for a certificateyou can spend $$ for a certificate
increased trust among your customersincreased trust among your customers
Signing a jarSigning a jar
Full details at end of slidesFull details at end of slides1.1. Create a key fileCreate a key file
2.2. Add your keys to the fileAdd your keys to the file
3.3. Sign the jar file with your keySign the jar file with your key
4.4. Only you can sign it this wayOnly you can sign it this way
5.5. For greater trust, buy a certificate $$For greater trust, buy a certificate $$
What happens when you What happens when you execute a jar file?execute a jar file?
1.1. java opens the jar file and looks in a java opens the jar file and looks in a directory called META-INFdirectory called META-INF
2.2. it finds the file MANIFEST.MFit finds the file MANIFEST.MF this was created from your manifest.txt filethis was created from your manifest.txt file
3.3. looks to see where the main() method islooks to see where the main() method is Main-Class: cs201.SimpleGUIMain-Class: cs201.SimpleGUI knows to look in the cs201 package directory knows to look in the cs201 package directory
(in the jar file)(in the jar file) look for the class SimpleGUIlook for the class SimpleGUI call the main() method inside of SimpleGUIcall the main() method inside of SimpleGUI
We can also include images, We can also include images, sounds, in the jar filesounds, in the jar file
Details shown at end:Details shown at end:1.1. put the file in your packageput the file in your package
2.2. use a URL to access the fileuse a URL to access the file
WebStart - STDGOADKWebStart - STDGOADK
Your app lives on the webYour app lives on the web You download it to your machineYou download it to your machine It executes on your machineIt executes on your machine Makes sure your version is up to dateMakes sure your version is up to date
can fetch updatescan fetch updates get fetch newer versions of the runtime get fetch newer versions of the runtime
system, etc. system, etc.
Web Start overviewWeb Start overview
create executable jar filecreate executable jar file sign itsign it create a JNLP filecreate a JNLP file create an html filecreate an html file put all this on a websiteput all this on a website
JNLP – java network launching JNLP – java network launching protocolprotocol
web-centricweb-centric "codebase" is on web, not users disk"codebase" is on web, not users disk something like running:something like running:
java –classpath java –classpath http://www.people.virginia.edu/~cwm2n/Simplehttp://www.people.virginia.edu/~cwm2n/SimpleGUI.jarGUI.jar cs201.SimpleGui cs201.SimpleGui
uses a JNLP file to guide the fetch and uses a JNLP file to guide the fetch and runrun
provides secure running (unless your provides secure running (unless your user gives permission)user gives permission)
JNLP fileJNLP file
xml – oh boyxml – oh boy specifies jar filespecifies jar file the java runtimethe java runtime any optional packagesany optional packages system propertiessystem properties URLs pointing to any resources (images, URLs pointing to any resources (images,
sounds, etc)sounds, etc) name of html file pointing to usname of html file pointing to us our name (i.e., SimpleGUI.jnlp)our name (i.e., SimpleGUI.jnlp)
Need a web page, tooNeed a web page, too
Either put into your index.html Either put into your index.html
or something as simple as:or something as simple as:
<a href="SimpleGUI.jnlp"><a href="SimpleGUI.jnlp">
Simple GUI WebStart ApplicationSimple GUI WebStart Application
</a></a>
Put into the file reference by the jnlp filePut into the file reference by the jnlp file
put all of this on a web pageput all of this on a web page
www.people.virginia.edu/~cwm2nwww.people.virginia.edu/~cwm2n i.e., in the public_html directory of your i.e., in the public_html directory of your
home directory file sharehome directory file share SimpleGUI.jarSimpleGUI.jar SimpleGUI.jnlpSimpleGUI.jnlp index.htmlindex.html
Run it via WebStartRun it via WebStart
or click on the linkor click on the link
www.people.virginia.edu/~cwm2n/Simwww.people.virginia.edu/~cwm2n/SimpleGUI.jnlppleGUI.jnlp
WebStartWebStart
Including the .gif in your Including the .gif in your projectproject
right click on the right click on the projectproject importimport file systemfile system nextnext
import from a import from a directory like c:\directory like c:\localdatalocaldata
importing a gif into projectimporting a gif into project
you will see a list of you will see a list of all filesall files
select select Olsson001.gifOlsson001.gif
importing a gif into projectimporting a gif into project
This will put file in This will put file in your project.your project.
You drag it to the You drag it to the packagepackage
in this picture, I've in this picture, I've already done soalready done so
importing a gif into importing a gif into projectproject
jar files from Eclipsejar files from Eclipse
exportexport jar filejar file select the resourcesselect the resources give it a name, like SimpleGUI.jargive it a name, like SimpleGUI.jar next look at packaging options (doesn't next look at packaging options (doesn't
matter)matter) next, generate a manifest file and specify the next, generate a manifest file and specify the
main() class: e.g.:cs201.SimpleGuimain() class: e.g.:cs201.SimpleGui click on finishclick on finish
Jar optionsJar options
Shown on next slidesShown on next slides
Jar optionsJar options
jar –cf SimpleGUI.jar cs201jar –cf SimpleGUI.jar cs201 -c means "create a jar"-c means "create a jar" f means "with the file name"f means "with the file name" SimpleGUI.jar is the name of the jar fileSimpleGUI.jar is the name of the jar file cs201 is the package directory that will cs201 is the package directory that will
be put into the jarbe put into the jar
Jar optionsJar options
jar –xf SimpleGUI.jar jar –xf SimpleGUI.jar -x means "extract a jar"-x means "extract a jar" f means "with the file name"f means "with the file name" SimpleGUI.jar is the name of the jar fileSimpleGUI.jar is the name of the jar file
Will extract the contents of the jar file Will extract the contents of the jar file (i.e., create the cs201 package (i.e., create the cs201 package directory and all the files therein)directory and all the files therein)
Jar optionsJar options
jar –tf SimpleGUI.jar jar –tf SimpleGUI.jar -x means "extract a jar"-x means "extract a jar" t means "display the contents"t means "display the contents" SimpleGUI.jar is the name of the jar fileSimpleGUI.jar is the name of the jar file
Will list contents of jar fileWill list contents of jar file
Executable jar files with Executable jar files with packagespackages
assume same set of class directoriesassume same set of class directories c:\Gift\cs201 is the package directoryc:\Gift\cs201 is the package directory
go to top level directorygo to top level directory cd c:\Giftcd c:\Gift create a manifest file, manifest.txt, that tells us create a manifest file, manifest.txt, that tells us
where the main() method is to be foundwhere the main() method is to be found Main-class: cs201.SimpleGUIMain-class: cs201.SimpleGUI
put manifest.txt in c:\Giftput manifest.txt in c:\Gift create the executable jar filecreate the executable jar file
jar –cvmf manifest.txt SimpleGUI.jar cs201jar –cvmf manifest.txt SimpleGUI.jar cs201 m in –cvmf means, include the manifest file m in –cvmf means, include the manifest file
(manifest.txt) in the jar(manifest.txt) in the jar
Signing a Jar file, part ISigning a Jar file, part I
keyskeys create a keystore to hold your keyscreate a keystore to hold your keys
keytool -genkey -keystore newKeys -alias team99keytool -genkey -keystore newKeys -alias team99 generates a keystore called myKeys and adds a holder generates a keystore called myKeys and adds a holder
cwm2ncwm2n prompt you for the password (echoes to screen)!prompt you for the password (echoes to screen)! Your name, organization, city, state, etc. Your name, organization, city, state, etc.
keytool -selfcert -alias team99 -keystore newKeyskeytool -selfcert -alias team99 -keystore newKeys -selfcert – informal-selfcert – informal -alias team99 who is signing this-alias team99 who is signing this -keystore where to put the keys -keystore where to put the keys
keytool -list -keystore newKeyskeytool -list -keystore newKeys how to see your keyshow to see your keys
Signing a Jar file, part IISigning a Jar file, part II
use jarsigneruse jarsigner jarsigner -keystore myKeys jarsigner -keystore myKeys
SimpleGUI.jar cwm2nSimpleGUI.jar cwm2n
How to access gifs, sounds in How to access gifs, sounds in the jar filethe jar file
Suppose is want to open a file in a method Suppose is want to open a file in a method of the class SimpleGUIof the class SimpleGUI ImageIcon img= new ImageIcon img= new
ImageIcon("Olsson001.gif");ImageIcon("Olsson001.gif"); Since jar file is running from the c:\Gift Since jar file is running from the c:\Gift
directory, might not find the .gif filedirectory, might not find the .gif file Do we put Olsson001.gif in c:\GiftDo we put Olsson001.gif in c:\Gift
if we do, and jar it up, this still does not work if we do, and jar it up, this still does not work since Olsson001.gif is not in the c:\Gift directorysince Olsson001.gif is not in the c:\Gift directory
How to access gifs, sounds in How to access gifs, sounds in the jar filethe jar file
Package to the rescue!Package to the rescue! put Olsson001.gif in cs201 package put Olsson001.gif in cs201 package
directorydirectory change statement to:change statement to: ImageIcon img= new ImageIcon img= new
ImageIcon("cs201/Olsson001.gif");ImageIcon("cs201/Olsson001.gif"); Now, java knows to look in the Now, java knows to look in the
package cs201 inside the jar filepackage cs201 inside the jar file Works!Works!
How to access gifs, sounds in How to access gifs, sounds in the jar filethe jar file
URL to the rescue!URL to the rescue! keep Olsson001.gif in cs201 package directorykeep Olsson001.gif in cs201 package directory change statements to:change statements to:
URL url = URL url = SimpleGUI.class.getResource("Olsson001.gif");SimpleGUI.class.getResource("Olsson001.gif");
Image img= Toolkit.getDefaultToolkit().getImage(url);Image img= Toolkit.getDefaultToolkit().getImage(url); need import java.net.*;need import java.net.*;
Now, java knows to look in the package Now, java knows to look in the package cs201 inside the jar filecs201 inside the jar file
Works!Works!
JNLP file specificsJNLP file specifics
line by line follows this slideline by line follows this slide
Line by line look at JNLP fileLine by line look at JNLP file
<?xml version "1.0" encoding="utf-8"?<?xml version "1.0" encoding="utf-8"?>>
using xml version 1 and the encoding using xml version 1 and the encoding we'll usewe'll use
Line by line Line by line
<jnlp spec="1.0"<jnlp spec="1.0"codebase="http://codebase="http://www.people.virginia.edu/~cwm2n"www.people.virginia.edu/~cwm2n"href="SimpleGUI.jnlp">href="SimpleGUI.jnlp">
version of jnlp to useversion of jnlp to use codebase is where the code livescodebase is where the code lives last line is required, seems redundant but last line is required, seems redundant but
useful if installed on desktopuseful if installed on desktop
Line by lineLine by line<information><information>
<title>Simple GUI App<title>Simple GUI App
</title></title>
<vendor>CS201 Teams Rule!<vendor>CS201 Teams Rule!
</vendor></vendor>
<homepage href="index.html"/><homepage href="index.html"/>
<description>Simple GUI webstart <description>Simple GUI webstart demo demo </description></description>
<offline-allowed/><offline-allowed/>
</information></information>
Line by lineLine by line
<security><security> <all-permissions/><all-permissions/></security></security>
Dangerous!Dangerous! you are asking for carte blancheyou are asking for carte blanche
read files, write files, read clipboard, etc. read files, write files, read clipboard, etc. user will allow this, even if you have user will allow this, even if you have
written poor code (and erase her disk!)written poor code (and erase her disk!)
Line by lineLine by line
<resources><resources>
<j2se version="1.4"/><j2se version="1.4"/>
<jar href="SimpleGUI.jar"/><jar href="SimpleGUI.jar"/>
</resources></resources> which version of java to usewhich version of java to use which executable jar filewhich executable jar file can include things like sounds and can include things like sounds and
imagesimages
Line by lineLine by line
<application-desc <application-desc
main-class="cs201.SimpleGUI"/>main-class="cs201.SimpleGUI"/>
Like the manifest file, tells which class Like the manifest file, tells which class has a main() methodhas a main() method
putting it all togetherputting it all together
<?xml version "1.0" encoding="utf-<?xml version "1.0" encoding="utf-8"?>8"?>
<jnlp spec="1.0"<jnlp spec="1.0"codebase=codebase=
"http://www.people.virginia.edu/"http://www.people.virginia.edu/~cwm2n"~cwm2n"href="SimpleGUI.jnlp">href="SimpleGUI.jnlp">
<information><information> <title>Simple GUI App</title><title>Simple GUI App</title> <homepage <homepage
href="index.html"/>href="index.html"/> <vendor>cwm2n</vendor><vendor>cwm2n</vendor> <description>Simple GUI <description>Simple GUI
webstart demowebstart demo </description></description>
</information></information>
<security><security> <all-permissions/><all-permissions/> </security></security> <resources><resources> <j2se version="1.4"/><j2se version="1.4"/> <jar <jar
href="SimpleGUI.jar"/>href="SimpleGUI.jar"/> </resources></resources><application-desc main-<application-desc main-
class="cs201.SimpleGUI"/>class="cs201.SimpleGUI"/></jnlp></jnlp>