CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Join Date
    Sep 2011
    Posts
    22

    How to make a WORKING .jar? (Eclipse)

    Hi everyone,
    I am new to these forums, I've been looking for an answer to this question for awhile so hopefully someone can help me out.
    I am relatively new to programming, I know my way around but have a lot to learn. I wrote a program the past two days to help me study my AP Chem terms so I can memorize them. The program is now fully functional and runs in Eclipse when i hit run. My question is how can i make my program run OUTSIDE of eclipse? I want to be able to make a .jar (or whatever is best) so that i can double click it and open it up. I assume it would have to use a command prompt or something (the program is ALL text, no jframes or anything like that) When I try to export it as a .jar file and run it, it shows up saying it failed to load the main class manifest and can't start. How can I make the program work? again all i want is to open a command prompt or something like that that displays text and allows user input of text. Hopefully you all understand what I am asking (It's difficult to describe). Please respond with your thoughts. Thanks again!

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    it shows up saying it failed to load the main class manifest and can't start.
    To execute a program in a jar file via the double click on the file, you need to have the OS execute the java command with the -jar option. The jar file must contain a manifest file with a Main-Class: record that refers to the class with the main() method that will start the program. Your IDE can be configured to generate all that.

    To get a console window, try making a batch file that will execute the jar file. Then create a shortcut that will execute the batch file.
    Norm

  3. #3
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    The .java file im making into a jar starts with this (showing it has a main() )
    public class CalcReview {

    public static void main(String[] args) {

    the .jar ONLY contains this file, there arent multiple .java files in it. so it has the main() in it already right? Forgive me, I'm new to all of this. As for the batch file, I would have no clue how to do that either =/ ill try to google it to find out more about it

  4. #4
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    i SEEM to have made some progress....i exported it differently and don't get the failed to find manifest error. I can't get the batch file to run. I type java -jar Myjar.jar and it returns that java is not recognized as an internal or external command. However that format is the only one i've found.....can you please recommend to me how to make a simple batch so it'll work?

  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    To make an executable jar file you need to put the .class files in it that are to be executed.

    You need to do some reading about how to create and use executable jar files.
    Norm

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    how to make a simple batch so it'll work
    Use the full path to the java.exe file in the batch file.
    Norm

  7. #7
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    I tried to run it now through the cmd and it must have worked but i got the message invalid or corrupt jar file....this is so difficult -.-

  8. #8
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    Can you copy the console here from when you try to execute it?
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Norm

  9. #9
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    java -jar "C:\myjarfile.jar"

    This is from the CMD.
    More information: When i export out of eclipse, I let it generate the manifest in CalcReview/bin/manifest (calcreview being the project of the jar). I don't know if this is wrong or not...I got the batch file working too. Everything now says invalid or corrupt jar file

  10. #10
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    C:\Users\Danny\Desktop>ECHO OFF
    Press any key to continue . . .

    Whoops, this is what i meant to write for the CMD's copy/paste. there's no edit button on these forums -.-

  11. #11
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    Can you copy ALL of the command prompt console window including the error message
    Norm

  12. #12
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    the error message doesn't show up in the console. it shows up as a new window. heres a ppic:



    Uploaded with ImageShack.us

  13. #13
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    Try opening the jar file in a zip file utility. Check that it contains .class file(s) and a manifest file.
    Norm

  14. #14
    Join Date
    Sep 2011
    Posts
    22

    Re: How to make a WORKING .jar? (Eclipse)

    I just did, It contains all of the .class files and the manifest...

  15. #15
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How to make a WORKING .jar? (Eclipse)

    Try executing the java command in the command prompt window and copying the contents of the window here.
    Norm

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured