Results 1 to 4 of 4
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default How to package a .class file into a .jar file?

    I wrote a HelloWorld class in a folder "D:\Workspaces\Workspace of Java Practice\Packaging Programs into JAR Files\src". I am trying to create a Jar file containing this HelloWorld.class file, following this. So I opened cmd in the src directory and executed the following command.

    Java Code:
    jar cv HelloWorld.jar HelloWorld.class
    I got this:

    Java Code:
    D:\Workspaces\Workspace of Java Practice\Packaging Programs i
    nto JAR Files\src>jar cv HelloWorld.jar HelloWorld.class
    HelloWorld.jar : no such file or directory
     δ╗H                    ♦ META-INF/■╩  ♥     ☻       PK♥ δ╗H               ME
    K-*╬╠╧│R0╘3ασr.JM,IM╤u♦        δ↓─[*h↨%&τ*8τ↨Σ↨% k≥rr☺ P╖qC   D   PK♥
     c╖H            ►   HelloWorld.classmPMK├@►}█|515╡╡⌡│P☼B1ŧ/x(*D⌠α)i▓%╔JL⌂
    ▲<♥ⁿQΓl╨▌}≤▐╠█■♦p♥‼₧6VΦ8Φb╒B╧B┴<▬(N↑4⌂∩A?S╬αE╞/╩4∙u'Φi$2╛⌂
    7₧GQD┘\d│↕:,≤      ?‼∞≤$╖2Oφ┬B╙┬ul0┤≥┴≡I◄v,l║╪┬6⌡e♀φz╠e<τΓ▼>?<
    ┌d∟♀6e♥▒*♫B ↓╙@EY√G▌%⌐BφW4:┌←⌠εT]5Ω‼╥,* P♥   Y!☺  ⌐☺  PK δ╗H    ☻
             ♦               META-INF/■╩  PK☺☻ δ╗H╖qC   D                =   ME
    TA-INF/MANIFEST.MFPK☺☻ c╖H♥   Y!☺  ⌐☺  ►             ┬   HelloWorld.classPK♣♠
        ♥ ♥ ╗   !☻
    D:\Workspaces\Workspace of Java Practice\Packaging Programs i
    nto JAR Files\src>
    Why is this happening? Did I make a mistake?
    Last edited by Zarah; 04-29-2016 at 12:14 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to package a .class file into a .jar file?

    Try jar cvf instead of just jar cv.
    The 'f' option tells the jar tool to send the output to the file specified (in this case HelloWorld.jar), without it it just sends it to stdout.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to package a .class file into a .jar file?

    Also, if you want to create an executable jar, you need to set the entry point in the manifest file. Check it out here.

    Setting an Application's Entry Point (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: How to package a .class file into a .jar file?

    @Jim829 OK, thank you very much.

Similar Threads

  1. Replies: 14
    Last Post: 11-25-2011, 04:25 PM
  2. Replies: 7
    Last Post: 10-04-2011, 05:16 AM
  3. How to Run four source file in a single package
    By krishanu in forum New To Java
    Replies: 0
    Last Post: 05-25-2011, 01:22 PM
  4. Replies: 6
    Last Post: 04-16-2011, 08:06 PM
  5. converting java class file to exe file
    By satheeshtech in forum Advanced Java
    Replies: 5
    Last Post: 07-18-2009, 11:47 PM

Posting Permissions

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