How to make an executable jar file?












58















I have a program which consists of two simple java swing files.



How do I make an executable jar file for my program?










share|improve this question

























  • What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

    – AlikElzin-kilaka
    May 10 '15 at 11:30











  • Related: superuser.com/questions/912955/…

    – AlikElzin-kilaka
    May 10 '15 at 11:55
















58















I have a program which consists of two simple java swing files.



How do I make an executable jar file for my program?










share|improve this question

























  • What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

    – AlikElzin-kilaka
    May 10 '15 at 11:30











  • Related: superuser.com/questions/912955/…

    – AlikElzin-kilaka
    May 10 '15 at 11:55














58












58








58


21






I have a program which consists of two simple java swing files.



How do I make an executable jar file for my program?










share|improve this question
















I have a program which consists of two simple java swing files.



How do I make an executable jar file for my program?







java jar executable-jar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 '17 at 19:17









River

5,40683651




5,40683651










asked Mar 10 '11 at 10:10









ReubenReuben

3,01463350




3,01463350













  • What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

    – AlikElzin-kilaka
    May 10 '15 at 11:30











  • Related: superuser.com/questions/912955/…

    – AlikElzin-kilaka
    May 10 '15 at 11:55



















  • What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

    – AlikElzin-kilaka
    May 10 '15 at 11:30











  • Related: superuser.com/questions/912955/…

    – AlikElzin-kilaka
    May 10 '15 at 11:55

















What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

– AlikElzin-kilaka
May 10 '15 at 11:30





What are you asking? How to execute the jar or how to create an executable from the jar(one command, like run.cmd)?

– AlikElzin-kilaka
May 10 '15 at 11:30













Related: superuser.com/questions/912955/…

– AlikElzin-kilaka
May 10 '15 at 11:55





Related: superuser.com/questions/912955/…

– AlikElzin-kilaka
May 10 '15 at 11:55












3 Answers
3






active

oldest

votes


















68














A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.



public class JarExample {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
// your logic here
}
});
}
}


Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,



Manifest-Version: 1.0
Main-Class: JarExample


Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)



jar cfm jarexample.jar jexample.mf *.class


It will create executable jarexample.jar.






share|improve this answer





















  • 26





    Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

    – Powerslave
    Mar 24 '15 at 10:35





















35














In Eclipse you can do it simply as follows :




Right click on your Java Project and select Export.



Select Java -> Runnable JAR file -> Next.



Select the Launch Configuration and choose project file as your Main class



Select the Destination folder where you would like to save it and click Finish.







share|improve this answer


























  • Launch Configuration: <MainClasssName> - <ProjectName>

    – lrn2prgrm
    Apr 14 '16 at 16:42



















6














Here it is in one line:



jar cvfe myjar.jar package.MainClass *.class


where MainClass is the class with your main method, and package is MainClass's package.



Note you have to compile your .java files to .class files before doing this.



c  create new archive
v generate verbose output on standard output
f specify archive file name
e specify application entry point for stand-alone application bundled into an executable jar file


This answer inspired by Powerslave's comment on another answer.






share|improve this answer
























    protected by Community Mar 13 '15 at 13:24



    Thank you for your interest in this question.
    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



    Would you like to answer one of these unanswered questions instead?














    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    68














    A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.



    public class JarExample {

    public static void main(String args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    // your logic here
    }
    });
    }
    }


    Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,



    Manifest-Version: 1.0
    Main-Class: JarExample


    Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)



    jar cfm jarexample.jar jexample.mf *.class


    It will create executable jarexample.jar.






    share|improve this answer





















    • 26





      Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

      – Powerslave
      Mar 24 '15 at 10:35


















    68














    A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.



    public class JarExample {

    public static void main(String args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    // your logic here
    }
    });
    }
    }


    Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,



    Manifest-Version: 1.0
    Main-Class: JarExample


    Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)



    jar cfm jarexample.jar jexample.mf *.class


    It will create executable jarexample.jar.






    share|improve this answer





















    • 26





      Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

      – Powerslave
      Mar 24 '15 at 10:35
















    68












    68








    68







    A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.



    public class JarExample {

    public static void main(String args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    // your logic here
    }
    });
    }
    }


    Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,



    Manifest-Version: 1.0
    Main-Class: JarExample


    Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)



    jar cfm jarexample.jar jexample.mf *.class


    It will create executable jarexample.jar.






    share|improve this answer















    A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.



    public class JarExample {

    public static void main(String args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    // your logic here
    }
    });
    }
    }


    Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,



    Manifest-Version: 1.0
    Main-Class: JarExample


    Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)



    jar cfm jarexample.jar jexample.mf *.class


    It will create executable jarexample.jar.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 '17 at 3:47









    River

    5,40683651




    5,40683651










    answered Mar 10 '11 at 10:25









    isurusndrisurusndr

    84675




    84675








    • 26





      Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

      – Powerslave
      Mar 24 '15 at 10:35
















    • 26





      Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

      – Powerslave
      Mar 24 '15 at 10:35










    26




    26





    Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

    – Powerslave
    Mar 24 '15 at 10:35







    Just my two cents: You do not necessarily have to create a manifest file. For the jar utility, if you specify the flag e instead of m, then you just need to specify the entry point (that is, the main class) of the application, rather than a manifest file. Example: jar cvfe jarexample.jar com.example.jar.JarExample *.class

    – Powerslave
    Mar 24 '15 at 10:35















    35














    In Eclipse you can do it simply as follows :




    Right click on your Java Project and select Export.



    Select Java -> Runnable JAR file -> Next.



    Select the Launch Configuration and choose project file as your Main class



    Select the Destination folder where you would like to save it and click Finish.







    share|improve this answer


























    • Launch Configuration: <MainClasssName> - <ProjectName>

      – lrn2prgrm
      Apr 14 '16 at 16:42
















    35














    In Eclipse you can do it simply as follows :




    Right click on your Java Project and select Export.



    Select Java -> Runnable JAR file -> Next.



    Select the Launch Configuration and choose project file as your Main class



    Select the Destination folder where you would like to save it and click Finish.







    share|improve this answer


























    • Launch Configuration: <MainClasssName> - <ProjectName>

      – lrn2prgrm
      Apr 14 '16 at 16:42














    35












    35








    35







    In Eclipse you can do it simply as follows :




    Right click on your Java Project and select Export.



    Select Java -> Runnable JAR file -> Next.



    Select the Launch Configuration and choose project file as your Main class



    Select the Destination folder where you would like to save it and click Finish.







    share|improve this answer















    In Eclipse you can do it simply as follows :




    Right click on your Java Project and select Export.



    Select Java -> Runnable JAR file -> Next.



    Select the Launch Configuration and choose project file as your Main class



    Select the Destination folder where you would like to save it and click Finish.








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 15 '13 at 10:07









    Laksh

    4,82152733




    4,82152733










    answered Mar 23 '13 at 14:02









    TwinscodeTwinscode

    36636




    36636













    • Launch Configuration: <MainClasssName> - <ProjectName>

      – lrn2prgrm
      Apr 14 '16 at 16:42



















    • Launch Configuration: <MainClasssName> - <ProjectName>

      – lrn2prgrm
      Apr 14 '16 at 16:42

















    Launch Configuration: <MainClasssName> - <ProjectName>

    – lrn2prgrm
    Apr 14 '16 at 16:42





    Launch Configuration: <MainClasssName> - <ProjectName>

    – lrn2prgrm
    Apr 14 '16 at 16:42











    6














    Here it is in one line:



    jar cvfe myjar.jar package.MainClass *.class


    where MainClass is the class with your main method, and package is MainClass's package.



    Note you have to compile your .java files to .class files before doing this.



    c  create new archive
    v generate verbose output on standard output
    f specify archive file name
    e specify application entry point for stand-alone application bundled into an executable jar file


    This answer inspired by Powerslave's comment on another answer.






    share|improve this answer






























      6














      Here it is in one line:



      jar cvfe myjar.jar package.MainClass *.class


      where MainClass is the class with your main method, and package is MainClass's package.



      Note you have to compile your .java files to .class files before doing this.



      c  create new archive
      v generate verbose output on standard output
      f specify archive file name
      e specify application entry point for stand-alone application bundled into an executable jar file


      This answer inspired by Powerslave's comment on another answer.






      share|improve this answer




























        6












        6








        6







        Here it is in one line:



        jar cvfe myjar.jar package.MainClass *.class


        where MainClass is the class with your main method, and package is MainClass's package.



        Note you have to compile your .java files to .class files before doing this.



        c  create new archive
        v generate verbose output on standard output
        f specify archive file name
        e specify application entry point for stand-alone application bundled into an executable jar file


        This answer inspired by Powerslave's comment on another answer.






        share|improve this answer















        Here it is in one line:



        jar cvfe myjar.jar package.MainClass *.class


        where MainClass is the class with your main method, and package is MainClass's package.



        Note you have to compile your .java files to .class files before doing this.



        c  create new archive
        v generate verbose output on standard output
        f specify archive file name
        e specify application entry point for stand-alone application bundled into an executable jar file


        This answer inspired by Powerslave's comment on another answer.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 13 '18 at 16:52

























        answered Nov 9 '17 at 19:16









        RiverRiver

        5,40683651




        5,40683651

















            protected by Community Mar 13 '15 at 13:24



            Thank you for your interest in this question.
            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



            Would you like to answer one of these unanswered questions instead?



            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre