+ 2
Java question?
So in c++, when I compile a program I get an exe file as a result. When I compile a Java program, I get class files that I can't run. I have to run it from the command prompt. How can I do something like an exe with Java? I'm pretty sure the Java equivalent is a jar file, correct me if i'm wrong. But creating a jar file and attempting to run it didn't work. https://code.sololearn.com/cmmY1eh183GV/#java here's the code i've tried all of this on.
6 Answers
+ 4
You need a runnable/executable jar file.
Eclipse:
Right click on your Java Project and select Export.
Select Java -> Runnable JAR file -> Next.
Select the Launch Configuration and choose project file as your Main class.
Select the Destination folder where you would like to save it and click Finish.
Other IDE's:
http://www.skylit.com/javamethods/faqs/createjar.html
Or search in google for "your IDE + runnable jar file"
+ 2
+ 1
What if i'm not using an IDE?
+ 1
This is how I did it
1.Write code and save as "WhatEver.java"
2. In the command prompt, change the directory to whatever the file is
3. Compile the code using javac "WhatEver.java". You should get at least 1 class file.
4. Create a text file titled "manifest" and simply write "Main-Class: WhatEver" and press enter TWICE
5. Run this command: "jar cvfm NameOfYourJar.jar manifest.txt (after manifest.txt, you'd add all of the class files seperated by spaces)
+ 1
Daniel Cooper i guess you did it right but use jar cfm instead of cvfm other everything is correct
+ 1
Also if you want to know the errors write the following statement "java -jar filename.jar" let me know if there is any problem
https://www.sololearn.com/discuss/1707624/?ref=app
https://www.sololearn.com/discuss/1725367/?ref=app