100 likes | 216 Views
Computer Science A 13: 31/3. CS A. From .java to .exe. - classpath - jar - resources - wrapper/launcher. classpath. Hvor java kigger efter klasser java –cp .;c:madslibjava …main-class. Jar files. Compress and collect several files in an archive (zip like)
E N D
From .java to .exe - classpath - jar - resources - wrapper/launcher
classpath Hvor java kigger efter klasser java –cp .;c:\mads\lib\java …main-class
Jar files Compress and collect several files in an archive (zip like) >jar cf HelloWorld.jar HelloWorld.class Run it: >java –cp HelloWorld.jar HelloWorld cp: classpath: HelloWorld.jar, Main class: HelloWorld
Access to resources BufferedImage image = JCanvas.loadImage(”pict.jpg”); Clip sound = JCanvas.loadClip(”sound.wav”); Find it in local directory – same as the class file. More robust approach:
Access to resources Access from a URL: BufferedImage image = JCanvas.loadImage( PlaySound.class.getResource(”pict.jpg”)); Clip sound = JCanvas.loadClip( PlaySound.class.getResource(”sound.wav”)); Find the main class (PlaySound), from that class create a URL of a ressource local to that class.
Jar files with resources Put class files an resources in a jar file: > jar cf PlaySound.jar *.class *.au > java –cp PlaySound.jar PlaySound Works if you access sounds using ”getResource”.
JSmooth Java program launcher: JSmooth: takes a .jar file, an .ico file and generates an exe file. The exe file locates a java runtime environment on the machine and run the jar-file
Running JSmooth Skeleton: Windowed wrapper Executable: Executable Binary: full name of exe file Executable Icon: full name of icon file Current Directory: full name of directory Application Main Class: main class Embedded jar: yes, jar file Menu: System: save as Menu: Project: compile
Jar to exe file PlaySound.exe can be played on other computers with jre (java runtime environment)