Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deployment via jars and Webstart. How do we distribute our application? Lab says you need to submit CD Lab says you need to submit CD Limitations of CD.

Similar presentations


Presentation on theme: "Deployment via jars and Webstart. How do we distribute our application? Lab says you need to submit CD Lab says you need to submit CD Limitations of CD."— Presentation transcript:

1 Deployment via jars and Webstart

2 How do we distribute our application? Lab says you need to submit CD Lab says you need to submit CD Limitations of CD Limitations of CD fixed size fixed size classes are fixed classes are fixed java vm requirement fixed java vm requirement fixed Granny can't run it in DesMoine Granny can't run it in DesMoine Maybe Granny likes to save money and use the library computer Maybe Granny likes to save money and use the library computer

3 (JAR) Java ARchive files based on pkzip (rename from boo.jar to boo.zip and it becomes a zip file) based on pkzip (rename from boo.jar to boo.zip and it becomes a zip file) holds: holds: class files class files information about the contained files information about the contained files can hold other stuff, like gifs! can hold other stuff, like gifs! Best of all Best of all can be made executable can be made executable application runs out of the jar file application runs out of the jar file don't have to unjar (unpack) it don't have to unjar (unpack) it

4 Example: SimpleGui.jar I have a project, called Gift I have a project, called Gift c:\Gift is the directory c:\Gift is the directory I have a package, called cs201 I have a package, called cs201 c:\Gift\cs201 is the directory containing: c:\Gift\cs201 is the directory containing: SimpleGUI.java SimpleGUI.java SimpleGUI.class SimpleGUI.class Olsson001.gif Olsson001.gif

5 Jar options (complete list at end of slides) jar –cf SimpleGUI.jar cs201 jar –cf SimpleGUI.jar cs201 create create jar –xf SimpleGUI.jar jar –xf SimpleGUI.jar extract extract jar –tf SimpleGUI.jar jar –tf SimpleGUI.jar list contents list contents

6 Make it executable See slides at end See slides at end need to include a file (manifest) that tells java where the main() method is need to include a file (manifest) that tells java where the main() method is jar –cvmf manifest.txt SimpleGUI.jar cs201 jar –cvmf manifest.txt SimpleGUI.jar cs201 m in –cvmf means, include the manifest file (manifest.txt) in the jar m in –cvmf means, include the manifest file (manifest.txt) in the jar

7 How to run the jar file double-click it double-click it or or java –jar SimpleGUI.jar java –jar SimpleGUI.jar

8 Trust Java security based on the Sandbox Java security based on the Sandbox we'll let you have limited access to system resources we'll let you have limited access to system resources you cannot read or write to local disk you cannot read or write to local disk you (usually) only read from the website from which you are downloaded you (usually) only read from the website from which you are downloaded can't attack other sites, e.g. can't attack other sites, e.g.

9 Increased security Signing a jar file Signing a jar file signifies who created it signifies who created it somewhat informal somewhat informal you can spend $$ for a certificate you can spend $$ for a certificate increased trust among your customers increased trust among your customers

10 Signing a jar Full details at end of slides Full details at end of slides 1. Create a key file 2. Add your keys to the file 3. Sign the jar file with your key 4. Only you can sign it this way 5. For greater trust, buy a certificate $$

11 What happens when you execute a jar file? 1. java opens the jar file and looks in a directory called META-INF 2. it finds the file MANIFEST.MF this was created from your manifest.txt file this was created from your manifest.txt file 3. looks to see where the main() method is Main-Class: cs201.SimpleGUI Main-Class: cs201.SimpleGUI knows to look in the cs201 package directory (in the jar file) knows to look in the cs201 package directory (in the jar file) look for the class SimpleGUI look for the class SimpleGUI call the main() method inside of SimpleGUI call the main() method inside of SimpleGUI

12 We can also include images, sounds, in the jar file Details shown at end: Details shown at end: 1. put the file in your package 2. use a URL to access the file

13 WebStart - STDGOADK Your app lives on the web Your app lives on the web You download it to your machine You download it to your machine It executes on your machine It executes on your machine Makes sure your version is up to date Makes sure your version is up to date can fetch updates can fetch updates get fetch newer versions of the runtime system, etc. get fetch newer versions of the runtime system, etc.

14 Web Start overview create executable jar file create executable jar file sign it sign it create a JNLP file create a JNLP file create an html file create an html file put all this on a website put all this on a website

15 JNLP – java network launching protocol web-centric web-centric "codebase" is on web, not users disk "codebase" is on web, not users disk something like running: something like running: java –classpath http://www.people.virginia.edu/~cwm2n/SimpleG UI.jar cs201.SimpleGui java –classpath http://www.people.virginia.edu/~cwm2n/SimpleG UI.jar cs201.SimpleGui http://www.people.virginia.edu/~cwm2n/SimpleG UI.jar http://www.people.virginia.edu/~cwm2n/SimpleG UI.jar uses a JNLP file to guide the fetch and run uses a JNLP file to guide the fetch and run provides secure running (unless your user gives permission) provides secure running (unless your user gives permission)

16 JNLP file xml – oh boy xml – oh boy specifies jar file specifies jar file the java runtime the java runtime any optional packages any optional packages system properties system properties URLs pointing to any resources (images, sounds, etc) URLs pointing to any resources (images, sounds, etc) name of html file pointing to us name of html file pointing to us our name (i.e., SimpleGUI.jnlp) our name (i.e., SimpleGUI.jnlp)

17 Need a web page, too Either put into your index.html or something as simple as: Simple GUI WebStart Application Simple GUI WebStart Application</a> Put into the file reference by the jnlp file

18 put all of this on a web page www.people.virginia.edu/~cwm2n www.people.virginia.edu/~cwm2n www.people.virginia.edu/~cwm2n i.e., in the public_html directory of your home directory file share i.e., in the public_html directory of your home directory file share SimpleGUI.jar SimpleGUI.jar SimpleGUI.jnlp SimpleGUI.jnlp index.html index.html

19 Run it via WebStart or click on the link or click on the link www.people.virginia.edu/~cwm2n/SimpleG UI.jnlp www.people.virginia.edu/~cwm2n/SimpleG UI.jnlp

20 WebStart

21

22

23 Including the.gif in your project right click on the project right click on the project import import file system file system next next import from a directory like c:\localdata import from a directory like c:\localdata

24 importing a gif into project you will see a list of all files you will see a list of all files select Olsson001.gif select Olsson001.gif

25 importing a gif into project This will put file in your project. This will put file in your project. You drag it to the package You drag it to the package in this picture, I've already done so in this picture, I've already done so importing a gif into project importing a gif into project

26 jar files from Eclipse export export jar file jar file select the resources select the resources give it a name, like SimpleGUI.jar give it a name, like SimpleGUI.jar next look at packaging options (doesn't matter) next look at packaging options (doesn't matter) next, generate a manifest file and specify the main() class: e.g.:cs201.SimpleGui next, generate a manifest file and specify the main() class: e.g.:cs201.SimpleGui click on finish click on finish

27 Jar options Shown on next slides Shown on next slides

28 Jar options jar –cf SimpleGUI.jar cs201 jar –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 file SimpleGUI.jar is the name of the jar file cs201 is the package directory that will be put into the jar cs201 is the package directory that will be put into the jar

29 Jar 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 file SimpleGUI.jar is the name of the jar file Will extract the contents of the jar file (i.e., create the cs201 package directory and all the files therein)

30 Jar 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 file SimpleGUI.jar is the name of the jar file Will list contents of jar file

31 Executable jar files with packages assume same set of class directories assume same set of class directories c:\Gift\cs201 is the package directory c:\Gift\cs201 is the package directory go to top level directory go to top level directory cd c:\Gift cd c:\Gift create a manifest file, manifest.txt, that tells us where the main() method is to be found create a manifest file, manifest.txt, that tells us where the main() method is to be found Main-class: cs201.SimpleGUI Main-class: cs201.SimpleGUI put manifest.txt in c:\Gift put manifest.txt in c:\Gift create the executable jar file create the executable jar file jar –cvmf manifest.txt SimpleGUI.jar cs201 jar –cvmf manifest.txt SimpleGUI.jar cs201 m in –cvmf means, include the manifest file (manifest.txt) in the jar m in –cvmf means, include the manifest file (manifest.txt) in the jar

32 Signing a Jar file, part I keys keys create a keystore to hold your keys create a keystore to hold your keys keytool -genkey -keystore newKeys -alias team99 keytool -genkey -keystore newKeys -alias team99 generates a keystore called myKeys and adds a holder cwm2n generates a keystore called myKeys and adds a holder cwm2n 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 newKeys keytool -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 newKeys keytool -list -keystore newKeys how to see your keys how to see your keys

33 Signing a Jar file, part II use jarsigner use jarsigner jarsigner -keystore myKeys SimpleGUI.jar cwm2n jarsigner -keystore myKeys SimpleGUI.jar cwm2n

34 How to access gifs, sounds in the jar file Suppose is want to open a file in a method of the class SimpleGUI Suppose is want to open a file in a method of the class SimpleGUI ImageIcon img= new ImageIcon("Olsson001.gif"); ImageIcon img= new ImageIcon("Olsson001.gif"); Since jar file is running from the c:\Gift directory, might not find the.gif file Since jar file is running from the c:\Gift directory, might not find the.gif file Do we put Olsson001.gif in c:\Gift Do we put Olsson001.gif in c:\Gift if we do, and jar it up, this still does not work since Olsson001.gif is not in the c:\Gift directory if we do, and jar it up, this still does not work since Olsson001.gif is not in the c:\Gift directory

35 How to access gifs, sounds in the jar file Package to the rescue! Package to the rescue! put Olsson001.gif in cs201 package directory put Olsson001.gif in cs201 package directory change statement to: change statement to: ImageIcon img= new ImageIcon("cs201/Olsson001.gif"); ImageIcon img= new ImageIcon("cs201/Olsson001.gif"); Now, java knows to look in the package cs201 inside the jar file Now, java knows to look in the package cs201 inside the jar file Works! Works!

36 How to access gifs, sounds in the jar file URL to the rescue! URL to the rescue! keep Olsson001.gif in cs201 package directory keep Olsson001.gif in cs201 package directory change statements to: change statements to: URL url = SimpleGUI.class.getResource("Olsson001.gif"); URL url = 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 cs201 inside the jar file Now, java knows to look in the package cs201 inside the jar file Works! Works!

37 JNLP file specifics line by line follows this slide line by line follows this slide

38 Line by line look at JNLP file using xml version 1 and the encoding we'll use using xml version 1 and the encoding we'll use

39 Line by line <jnlp spec="1.0" codebase="http://www.people.virginia.edu/~cw m2n" href="SimpleGUI.jnlp"> version of jnlp to use version of jnlp to use codebase is where the code lives codebase is where the code lives last line is required, seems redundant but useful if installed on desktop last line is required, seems redundant but useful if installed on desktop

40 Line by line <information> Simple GUI App Simple GUI App</title> CS201 Teams Rule! CS201 Teams Rule!</vendor> Simple GUI webstart demo Simple GUI webstart demo <offline-allowed/></information>

41 Line by line <security> </security> Dangerous! Dangerous! you are asking for carte blanche you 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 written poor code (and erase her disk!) user will allow this, even if you have written poor code (and erase her disk!)

42 Line by line <resources> </resources> which version of java to use which version of java to use which executable jar file which executable jar file can include things like sounds and images can include things like sounds and images

43 Line by line <application-descmain-class="cs201.SimpleGUI"/> Like the manifest file, tells which class has a main() method

44 putting it all together <jnlp spec="1.0" codebase="http://www.people.virginia.edu/~cwm2n"href="SimpleGUI.jnlp"><information> Simple GUI App Simple GUI App cwm2n cwm2n Simple GUI webstart demo Simple GUI webstart demo <security> </jnlp>


Download ppt "Deployment via jars and Webstart. How do we distribute our application? Lab says you need to submit CD Lab says you need to submit CD Limitations of CD."

Similar presentations


Ads by Google