100 likes | 226 Vues
This guide details how to convert Java JAR files to executable EXE files using JSmooth. It covers the importance of specifying the classpath for resource access, such as images and sound files, utilizing methods like `JCanvas.loadImage()` and `JCanvas.loadClip()`. With JSmooth, you'll learn how to set up the EXE file to locate a Java Runtime Environment, ensuring your application runs seamlessly on any machine. Get step-by-step instructions for compiling your JAR into an EXE with essential resource management strategies.
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)