+ 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.

26th Feb 2019, 10:27 PM
Daniel Cooper
Daniel Cooper - avatar
6 odpowiedzi
+ 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"
26th Feb 2019, 10:49 PM
Denise Roßberg
Denise Roßberg - avatar
26th Feb 2019, 11:07 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
What if i'm not using an IDE?
26th Feb 2019, 11:00 PM
Daniel Cooper
Daniel Cooper - avatar
+ 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)
27th Feb 2019, 2:37 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Daniel Cooper i guess you did it right but use jar cfm instead of cvfm other everything is correct
31st Mar 2019, 3:48 PM
Rajb957
Rajb957 - avatar
+ 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
31st Mar 2019, 3:50 PM
Rajb957
Rajb957 - avatar