Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 23 of 23

Thread: got all .java files ready. how to make them into jar?

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default got all .java files ready. how to make them into jar?

    so how i can make them into jar?


  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?


  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    but when i try to run it it says cant find main-class -.-

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,619
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: got all .java files ready. how to make them into jar?

    1) Compile all of the .java files to create .class files.
    2) Create a zip folder.
    3) Put all of your .class files into the zip folder.
    4) Create a folder named (case sensitive): META-INF
    5) Create a .mf file named (case sensitive): MANIFEST and put in META-INF folder. Here is a copy of a manifest from one of my programs:
    Manifest-Version: 1.0
    Created-By: 1.6.0_14 (Sun Microsystems Inc.)
    Class-Path: SX.jar
    Main-Class: EventData

    The Class-Path variable indicates any external libraries you are using and provides full paths to those libraries. For this example, it is saying that the SX.jar library is in the same folder as the executing jar. The Main-Class variable indicates the name of the .class file inside the jar that will be the class with your main. Notice how there is no extension on on the Main-Class variable. Lastly, make sure there is at least 1 extra blank line at the bottom.
    6) Put the META-INF folder inside your zip folder.
    7) Rename the zip folder to be a .jar instead of a .zip.
    8) Double-click to run program.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by aussiemcgr View Post
    1) Compile all of the .java files to create .class files.
    2) Create a zip folder.
    3) Put all of your .class files into the zip folder.
    4) Create a folder named (case sensitive): META-INF
    5) Create a .mf file named (case sensitive): MANIFEST and put in META-INF folder. Here is a copy of a manifest from one of my programs:

    The Class-Path variable indicates any external libraries you are using and provides full paths to those libraries. For this example, it is saying that the SX.jar library is in the same folder as the executing jar. The Main-Class variable indicates the name of the .class file inside the jar that will be the class with your main. Notice how there is no extension on on the Main-Class variable. Lastly, make sure there is at least 1 extra blank line at the bottom.
    6) Put the META-INF folder inside your zip folder.
    7) Rename the zip folder to be a .jar instead of a .zip.
    8) Double-click to run program.
    tell me how i compile them?

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,619
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Do you have an IDE? Such as Eclipse, Netbeans, JCreator, ect. If so, you just have to find the .class files that are made when you compile your program in the IDE.

    If you do not have an IDE, you can use the Windows Command Prompt (if you run Windows) to compile the .java files and create .class files.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  7. #7
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by aussiemcgr View Post
    Do you have an IDE? Such as Eclipse, Netbeans, JCreator, ect. If so, you just have to find the .class files that are made when you compile your program in the IDE.

    If you do not have an IDE, you can use the Windows Command Prompt (if you run Windows) to compile the .java files and create .class files.
    umm okay i have eclipse where u can compile the files but there is a problem :/
    it gives alot of errors coz there is different .jar file where is the rest of the methods... so i need to know how to add it there but not inside the project witch i made? so it would use other .jar methods?
    Last edited by sibbe; December 4th, 2010 at 01:50 PM.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: got all .java files ready. how to make them into jar?

    In Eclipse, right click the project and go to Export. Go to Java->Runnable Jar (if you want a runnable jar). In the following window, choose your class containing the main method you wish to launch with, select how to repackage any external jar files, and define where to save the jar. Click Finish.

  9. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (December 6th, 2010)

  10. #9
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by copeg View Post
    In Eclipse, right click the project and go to Export. Go to Java->Runnable Jar (if you want a runnable jar). In the following window, choose your class containing the main method you wish to launch with, select how to repackage any external jar files, and define where to save the jar. Click Finish.
    too bad runnable jar file dont work for me :/
    and can you explain lidle bit more?

  11. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by sibbe View Post
    too bad runnable jar file dont work for me :/
    and can you explain lidle bit more?
    By 'doesn't work' I presume it doesn't launch. Go to the command line and try running the jar from there

    java -jar nameofjar.jar

    I suggest this because using the command line you can readily see any exceptions thrown which could be a reason why it is not launching.

  12. #11
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by copeg View Post
    By 'doesn't work' I presume it doesn't launch. Go to the command line and try running the jar from there

    java -jar nameofjar.jar

    I suggest this because using the command line you can readily see any exceptions thrown which could be a reason why it is not launching.
    no i meant the option in eclipse dont work <.<

  13. #12
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by sibbe View Post
    no i meant the option in eclipse dont work <.<
    Doesn't work can mean many things. Please define in detail what you mean by 'doesn't work'.

  14. #13
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by copeg View Post
    Doesn't work can mean many things. Please define in detail what you mean by 'doesn't work'.
    now it works :L but it says still that dont find main class :SS

  15. #14
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: got all .java files ready. how to make them into jar?

    Do you have a main method defined, or is this just a class library? If it's the latter, you can create a simple main method in one of your classes and declare it to do nothing. You can also try using the export as a Jar (not a Runnable Jar).
    public class SomeClass
    {
        public static void main(String[] args)
        {}
        // ... other code
    }

  16. #15
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by helloworld922 View Post
    Do you have a main method defined, or is this just a class library? If it's the latter, you can create a simple main method in one of your classes and declare it to do nothing. You can also try using the export as a Jar (not a Runnable Jar).
    public class SomeClass
    {
        public static void main(String[] args)
        {}
        // ... other code
    }
    kk now it wont give anyerror when i click the jar but it wont open anything?
    it supposed to open a game client so how i can make that that jar opens another jar too?

  17. #16
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    pleaseany1?

  18. #17
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: got all .java files ready. how to make them into jar?

    It won't do anything because it's defined to do nothing

    You need to put code inside the main method to launch the game client (I have no idea what this would be, though).

  19. #18
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    Quote Originally Posted by helloworld922 View Post
    It won't do anything because it's defined to do nothing

    You need to put code inside the main method to launch the game client (I have no idea what this would be, though).
    it is there coz i unpacked a jar coz i wanted to add few more options in it.
    but when i try repacking into jar it wont open :/

    edit:
    just tried just unpack a jar then tried repacking it into jar and now it wont open <.<

  20. #19
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    okey i found the problem...
    the problem is that the eclipse gives compile errors when i try make it into .class file and thats why it wont make that full java code inside to the .class... but the client works with that code witch is in the eclipse but i cant get it into .class file :/ so any ideas how to convert it into .class file with errors etc?

  21. #20
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: got all .java files ready. how to make them into jar?

    make sure you have imported the external .jar file you are using into your eclipse project,

    Project > Properties > Build Path > Libraries > add Jar
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  22. #21
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    now i cant modify it at all.... when i modifield it and export them to runnable jar it makes them back to the original code -.-
    i need modify it :/ so any other ideas?

  23. #22
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    it replaces the code where error appears with this:
     public final void createFrame()
      {
        throw new Error("Unresolved compilation problem: \n\tThe constructor Class26(int, int, Component, int) is undefined\n");
      }
     
      public final void createMenu()
      {
        throw new Error("Unresolved compilation problems: \n\tThe constructor Object(Menu) is undefined\n\tval$scriptMenu cannot be resolved or is not a field\n");
      }
    do i need to fix it or is there any way to that it wont replace that code with that error :/
    and if i need fix it? How i can do it?

    atm menu code is this:
     thiever.addActionListener(new ActionListener(scriptMenu)
          {
            public void actionPerformed(ActionEvent arg0) {
              while (true) {
                if (BSBotClient.username == null ? "" != null : !BSBotClient.username.equals("")) if (BSBotClient.password == null ? "" != null : !BSBotClient.password.equals(""))
                    break; BSBotClient.username = JOptionPane.showInputDialog("Enter username:");
                BSBotClient.password = JOptionPane.showInputDialog("Enter password:");
                if (BSBotClient.username == null ? "" != null : !BSBotClient.username.equals("")) if (BSBotClient.password == null ? "" != null : !BSBotClient.password.equals(""))
                    continue;
                JOptionPane.showMessageDialog(null, "Please enter something atleast");
              }
     
              BSBot.bsBot.scriptHandler.playScript(new BSScriptPaladinThiever(BSBot.bsBot));
              this.val$scriptMenu.setEnabled(false);
            }
          });

  24. #23
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got all .java files ready. how to make them into jar?

    bumbbumbumbumbumbnumb

Similar Threads

  1. How to create directory in Java?
    By JavaPF in forum Java Programming Tutorials
    Replies: 2
    Last Post: December 24th, 2011, 11:53 AM
  2. Replies: 0
    Last Post: June 18th, 2010, 07:18 AM
  3. Getting ready for an interview
    By Charlie in forum The Cafe
    Replies: 5
    Last Post: June 4th, 2010, 07:25 PM
  4. make dir using mkdir() in java io
    By mssi in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 6th, 2010, 04:51 PM
  5. Calling exe files from Java
    By linuxrockers in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 26th, 2010, 04:20 AM