-
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!
-
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.
-
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
-
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?
-
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.
-
Re: How to make a WORKING .jar? (Eclipse)
Quote:
how to make a simple batch so it'll work
Use the full path to the java.exe file in the batch file.
-
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 -.-
-
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.
-
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
-
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 -.-
-
Re: How to make a WORKING .jar? (Eclipse)
Can you copy ALL of the command prompt console window including the error message
-
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:
http://img18.imageshack.us/img18/8643/errorpov.png
Uploaded with ImageShack.us
-
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.
-
Re: How to make a WORKING .jar? (Eclipse)
I just did, It contains all of the .class files and the manifest...
-
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.
-
Re: How to make a WORKING .jar? (Eclipse)
The java command? sorry I don't know what you mean. Is that a specific file in the jar?
-
Re: How to make a WORKING .jar? (Eclipse)
java -jar <JARFILENAME>.jar
-
Re: How to make a WORKING .jar? (Eclipse)
The java command? I don't know what that is....Is it a specific file in the jar?
-
Re: How to make a WORKING .jar? (Eclipse)
-
Re: How to make a WORKING .jar? (Eclipse)
I just typed what you put into the cmd and got this...i don't know if that's what you mean:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Danny>APCHEM.jar
C:\Users\Danny>
C:\Users\Danny>java -jar APCHEM.jar
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Danny>
-
Re: How to make a WORKING .jar? (Eclipse)
You need to have the full path the java.exe file
just the same as I asked you to use in the batch file.
-
Re: How to make a WORKING .jar? (Eclipse)
I don't have a .exe program....I'm assuming you mean the .jar. And when i run the .bat file which runs it it just says invalid/corrupt jar
-
Re: How to make a WORKING .jar? (Eclipse)
If you do not have the java.exe file, you can NOT execute a jar file.
What command did you put in the batch file?
The java.exe file comes with the JDK.
-
Re: How to make a WORKING .jar? (Eclipse)
i put this in the batch:
ECHO OFF
C:\Users\Danny\APCHEM.jar
PAUSE
all I did was export through eclipse. I don't know exactly where I should be searching for a java.exe
-
Re: How to make a WORKING .jar? (Eclipse)
Do you have the JDK installed? It has a bin folder and inside there is the java.exe program.
-
Re: How to make a WORKING .jar? (Eclipse)
alright well i found the java.exe in the bin folder....i double clicked it and it pops up and goes away. what exactly do you want me to do?
-
Re: How to make a WORKING .jar? (Eclipse)
You need to find a tutorial that explains how to use the java command and how to set up and use jar files.
It's late and I'm done for the night.
Good luck
-
Re: How to make a WORKING .jar? (Eclipse)
alright my laptop's about to die anyway. Thank you for all of your help I'll look into it more.