How to run Java programs by clicking on their icon on Windows?

后端 未结 12 2624
太阳男子
太阳男子 2020-12-01 22:52

I have written a Java program that uses Java swing library. Now I would like to execute this program by double clicking on the executable file on Windows just like any other

相关标签:
12条回答
  • 2020-12-01 23:14

    While the others mention excellent choices like creating a native executable, there is another useful method: creating a shortcut.

    • Right click your desktop, expand the "New" option, and click on "Shortcut".
    • Type "javaw.exe". Click next.
    • Name it whatever you want. Click done.
    • You'll notice the newly created shortcut on your desktop. Right click it and choose "Properties"
    • In the "Target" textfield, append "-jar path-to-your-jar.jar" where you replace "path-to-your-jar.jar" with the actual path to your jar
    • You can also now optionally change the icon to whatever icon you want

    This shortcut can be pinned to the taskbar and be used from anywhere (considering you provided an absolute path to your JAR).

    0 讨论(0)
  • 2020-12-01 23:17

    Seems you want to deploy and run the standalone application of swings. Being a java developer you should understand the power of jar files. Those are executable in themselves {so no need to create .exe files :)} .

    The below code will help you to create a jar file.

    Creating a jar File in Command Prompt

    Start Command Prompt.
    Navigate to the folder that holds your class files:
    C:\>cd \mywork
    Set path to include JDK’s bin.  For example:
    C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%
    Compile your class(es):
    C:\mywork> javac *.java
    Create a manifest file:
    C:\mywork> echo Main-Class: NameOfProject >manifest.txt
    Create a jar file:
    C:\mywork> jar cvfm NameOfProject.jar manifest.txt *.class
    Test your jar:
    C:\mywork> DanceStudio.jar
    

    After creating a jar just double click on it and you are done.

    0 讨论(0)
  • 2020-12-01 23:19

    There are a few projects, like http://jsmooth.sourceforge.net/ and http://launch4j.sourceforge.net/

    0 讨论(0)
  • 2020-12-01 23:22

    Since it is Java based and has a GUI, the obvious answer is to deploy it using Java Web Start.

    Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.

    JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

    By 'desktop integration' read desktop shortcuts and menu items on supported platforms.

    Desktop Icons on Windows 7

    The 2 icons on the right (JotPad & Star Zoom Animation) are both Java based apps., installed using Java Web Start. Since JotPad is sand-boxed, the user will be prompted as to whether to create the shortcut. That choice is not offered for apps. with higher permission levels, so it would make more sense to install/remove the shortcuts and menu items using the IntegrationService - which allows an app. (after prompting the user) to create/remove them at run-time.

    0 讨论(0)
  • 2020-12-01 23:22

    You have to create an executable jar file. For that you just simply add a META-INF folder to the jar, then add a MANIFEST.MF text file with two lines:

    Manifest-Version: 1.0
    Main-Class: your.package.YourMainClass
    
    0 讨论(0)
  • 2020-12-01 23:27

    There are number of options:

    1. Create an executable jar of your project. for this jar to work you have to have javaw as default application to open it.
    2. Create an exe of your project.
    3. Create a bat file which runs your jar file.

    Take a look at this: How can I convert my Java program to an .exe file?

    0 讨论(0)
提交回复
热议问题