java executable jar creation

前端 未结 5 1868
情话喂你
情话喂你 2021-01-15 04:54

How to Create Executable jar file from .java file. Having only one java file dm.java which created using awt and applet. I need to create executable jar with icon or with im

5条回答
  •  花落未央
    2021-01-15 05:22

    When you create a executable .jar with a manifest that contains Main-Class: , it will work by double clicking BUT ONLY if you have the correct file associations setup on your system. For this to be correct, you need to install a RECENT version of Java. Some of the older versions of Java wont setup the file association that your end-user needs. You can guarantee it will work only by providing them a batch script that creates the file association, like so:

    @ECHO off
    SETLOCAL ENABLEDELAYEDEXPANSION
    :: this .bat script creates a file association for executable .jar files
    ECHO Creating .jar file association...
    ECHO JAVA_HOME is %JAVA_HOME%
    IF NOT DEFINED JAVA_HOME GOTO :FAIL
    REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
    REG ADD "HKCR\jarfile\shell" /ve /f
    REG ADD "HKCR\jarfile\shell\open" /ve /f
    ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
    REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f
    REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
    REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f
    REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f
    REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
    ECHO Finished creating .jar file association for executable .jar files.
    PAUSE
    GOTO EOF
    :FAIL
    ECHO Script failed. JAVA_HOME not defined.
    PAUSE
    

提交回复
热议问题