launch4j 与 inno setup 打包java桌面应用程序

      最近在做一个对java桌面应用程序项目,需要打包成同普通的二进制应用程序一样。

      [1]使用eclipse 将整个项目打包成可运行的jar文件,在应用过程中发现资源文件如果不是通过inputstream来读取的话,是无法访问到的,在做项目时没有考虑到这点,所以最后只好把资源拷出来,只对类文件进行打包。

 

          目录结构:

           |-soft

                |- soft.jar

                |-native dll

                |-jre

                |-resources

                    |-images

 

           原来的项目结构是

           |-src

                |-main

                     |-swingExe.java    //main主文件

                     |-panel

                     |-player

                 |-resources

                     |-images

 

           可见打包后的文件目录还是跟外界的保持一致的调用关系,另外这里提一点关于资源文件路径的问题,由于我是使用了 

    String rootpath = ClassLoader.getSystemResource("")来取得项目根目录的绝对路径的,在发布项目后,我发现这样

    取出来的路径上有的空格会被转换成为%20这样的编码,在读取时:File file = new File(rootpath+resourcespath)时,

   这个file是不存在的,最后只好再替换回来,不是太了解这里面的沟沟,有时间要好好的去看一下怎么回事。

 

 

     [2]使用launch4j把JAR文件转成exe文件。这里没什么好说的,就是填一下路径和文件名称,普通需要用到的只有三个tabs:

         basic , jre,splash;

 

     basic里面需要填写的是转成的exe保存路径,jar的路径以及icon

 

     jre,由于我是直接把jre拷到项目文件夹下了,所以只要填入./jre就行了,使用相对路径;启动文件会在当前目录查找jre,如果

       找不到,就会去父目录,最后才去查找注册表,看看是否有jre;如果都没有,就会打开下载网页,这个网页路径在basic里

    面有得填。

  splash,启动图片,就像eclipse这样的等待界面,填一个就好了`也可以不填的

 

    最后点那个齿轮就可以生成一个二进制的启动程序。

 

     [3] 使用inno setup打包安装程序,如果只是简单的安装程序,那直接使用它的向导就行了,这个我也不是太在行,看例子吧

 

    ; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! [Setup] ; NOTE: The value of AppId uniquely identifies this application. ; Do not use the same AppId value in installers for other applications. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) AppId={{E4577325-390A-48A4-9109-59D0ABBB2837} AppName=软件名称 AppVerName=版本 V1.0 AppPublisher=公司, Inc. DefaultDirName={pf}/ensoft DefaultGroupName=集团名 OutputDir=F:/ensofts OutputBaseFilename=setup SetupIconFile=F:/ensofts/favicon.ico Compression=lzma SolidCompression=yes [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files];解压的文件 Source: "F:/ensofts/jmf/*"; DestDir: "{sys}"; Flags: restartreplace sharedfile Source: "F:/ensofts/ensoft.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "F:/ensofts/atl2k.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "F:/ensofts/atl98.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "F:/ensofts/favicon.ico"; DestDir: "{app}"; Flags: ignoreversion Source: "F:/ensofts/jflash.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "F:/ensofts/resource/*"; DestDir: "{app}/resource"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "F:/ensofts/jre/*"; DestDir: "{app}/jre"; Flags: ignoreversion recursesubdirs createallsubdirs ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons];快捷方式 Name: "{group}/软件名称[启动菜单里的]"; Filename: "{app}/ensoft.exe";WorkingDir:"{app}" Name: "{commondesktop}/软件名称"; Filename: "{app}/ensoft.exe";Tasks: desktopicon;WorkingDir:"{app}" Name: "{group}/软件名称卸载"; Filename: "{app}/unins000.exe" [Run];安装完后运行 Filename: "{app}/ensoft.exe"; Description: "{cm:LaunchProgram,软件名称}"; Flags: nowait postinstall skipifsilent [Registry];注册表 Root: HKLM; Subkey: "Software/JavaSoft/Prefs/ensoft"; Flags: uninsdeletekeyifempty Root: HKLM; Subkey: "Software/JavaSoft/Prefs/ensoft"; ValueType: string; ValueName: "path"; ValueData: "{src}" Root: HKLM; Subkey: "Software/JavaSoft/Prefs/ensoft"; ValueType: string; ValueName: "register"; ValueData: "123456789" [UninstallDelete];清除项 Type: files; Name: "{sys}/jmacm.dll" Type: files; Name: "{sys}/jmam.dll" Type: files; Name: "{sys}/jmcvid.dll" Type: files; Name: "{sys}/jmdaud.dll" Type: files; Name: "{sys}/jmdaudc.dll" Type: files; Name: "{sys}/jmddraw.dll" Type: files; Name: "{sys}/jmfjawt.dll" Type: files; Name: "{sys}/jmg723.dll" Type: files; Name: "{sys}/jmgdi.dll" Type: files; Name: "{sys}/jmgsm.dll" Type: files; Name: "{sys}/jmh261.dll" Type: files; Name: "{sys}/jmh263enc.dll" Type: files; Name: "{sys}/jmjpeg.dll" Type: files; Name: "{sys}/jmmci.dll" Type: files; Name: "{sys}/jmmpa.dll" Type: files; Name: "{sys}/jmmpegv.dll" Type: files; Name: "{sys}/jmutil.dll" Type: files; Name: "{sys}/jmvcm.dll" Type: files; Name: "{sys}/jmvfw.dll" Type: files; Name: "{sys}/jmvh263.dll" Type: files; Name: "{sys}/jsound.dll"

 

 

 

    注:快捷方式那里要注意的就是一个workdir属性,因为有好多软件都是需要一个启始位置设定才可以正常运行的,这个属性就是了

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

你可能感兴趣的:(java(c/s))