Results 1 to 5 of 5
  1. #1
    Riaz Ali is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default How to create java executable file through CMD

    I want to create java executable (jar) file through command line. Can anyone kindly tell me STEP-BY-STEP how to do so

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,447
    Rep Power
    25

    Default

    First create a java program, compile it and test it.
    Create a manifest file with the Main-Class: entry
    Read the API doc for the syntax for the jar command.
    And/Or do a Google on how to use the jar command.
    Use the jar command to create the jar file.

    There are some posts on this forum showing how to use the jar file.

    Here's a batch file I use to create a jar file:
    EM Make SearchFiles.jar file
    %DEV_DRIVE%

    cd %DEV_HOME%\JavaDevelopment\
    jar -cmf NormsDev\SearchFiles\SearchFiles.mnf %JAVA_RUN%\SearchFiles.jar NormsDev\SearchFiles\SearchFiles*.class NormsDev\SearchFiles\SearchString*.class NormsDev\FilesIndex\FilesIndexReader*.class NormsDev\FilesIndex\ReferencesStore*.class NormsDev\HTMLStringDefs.class

    Rem No path for the Applet

    cd NormsDev\SearchFiles
    jar -uf %JAVA_RUN%\SearchFiles.jar SearchApplet*.class

    @REM Now pick up the Tools it needs:

    cd %DEV_HOME%\JavaDevelopment\
    jar -uf %JAVA_RUN%\SearchFiles.jar NormsTools\ErrDialog*.class NormsTools\ShowCounters*.class NormsTools\MakeEnterDoAction*.class NormsTools\MessageArea*.class NormsTools\IntInputField*.class NormsTools\ArrayUtil*.class NormsTools\MyLabel*.class NormsTools\FindOurHome*.class NormsTools\BrowserControl*.class NormsTools\ShowMsgBox*.class NormsTools\ShowListBox*.class NormsTools\ChoiceOfYesOrNo*.class NormsTools\ParsePath*.class NormsTools\InJar\*.class NormsTools\MyPreferences*.class NormsTools\UC_a_to_z*.class
    @ECHO ---- Created: %Java_RUN%\SearchFiles.jar ----
    @ECHO Remember to copy to \www for server
    MORE

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    finn is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    you have to tell the jar-file about the main methode. First you make a txt-file and you write: Main-Class: YourMainClassName Remember to end the txt file with a emty line. Then you put the txt-file and all the class-files in the same directory. Finely you go by command line to that directory and do this: jar cfm my.jar my.txt *.class

    The my.txt file content will be added to the jar-file manifest-file, and the file will be executable.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Even in some cases, you have to set those parameters in an IDE, if you are using any. Understanding of those basis is really helpful to deals with IDEs I guess.

Similar Threads

  1. How do I make a Java file executable
    By jacatone in forum Java Applets
    Replies: 13
    Last Post: 01-30-2014, 06:27 PM
  2. Executable File.
    By BeeGee in forum Advanced Java
    Replies: 13
    Last Post: 05-25-2010, 12:35 PM
  3. Replies: 0
    Last Post: 04-28-2010, 03:33 PM
  4. Create Executable problem
    By castiel in forum New To Java
    Replies: 13
    Last Post: 02-24-2010, 03:04 PM
  5. Executable java to read and write to a txt file
    By njoymirror in forum New To Java
    Replies: 2
    Last Post: 03-21-2009, 01:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •