Dear fellow java enthusiast,
I would like to make my java program into a executable .jar file with the help of eclipse. I exported into a .jar file but when I double click it it does not seem to work? I think i am missing something but after some time trying to find how to do it i cant find it.
Any advice?
import java.util.Scanner;
public class GravityMoon {
public static void main(String[] args) {
System.out.println("Please enter your earthweight in kilograms below:");
Scanner earthweight = new Scanner(System.in);
// Repeat until next item is a double
while (!earthweight.hasNextDouble())
{
// Read and discard offending non-double input
earthweight.next();
// Re-prompt
System.out.print("Please enter your earthweight "
+ "in numerical kilograms: ");
}
double moonweight;
// Converts earthweight in moonweight 17%
moonweight = earthweight.nextDouble() * 0.17;
// convert to whole numbers
//closes keyboard input
earthweight.close();
//prints out your moonweight in a decimal number
System.out.println("Your moonweight is " + Math.round(moonweight * 100d) /100d
+ " kilograms.");
}}
as you did not explain the exact problem, I might only give hints:
Export as Executable Jar
In Eclipse, there is the option to export into a jar file and another option to export into an executable jar file (see http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-37.htm ).
(I guess you are using windows) Try to execute the jar file from the console (something like java -jar ).
Double klicking a jar file in windows does not open a terminal window.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.