【问题标题】:Cannot make my program executable when using Ecplipse export使用 Eclipse 导出时无法使我的程序可执行
【发布时间】:2016-02-24 03:29:01
【问题描述】:

亲爱的java爱好者,

我想在 eclipse 的帮助下将我的 java 程序变成一个可执行的 .jar 文件。我导出到一个 .jar 文件,但是当我双击它时它似乎不起作用?我想我错过了一些东西,但经过一段时间试图找到如何去做我找不到它。

有什么建议吗?

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.");

        }}

【问题讨论】:

    标签: java file jar makefile executable


    【解决方案1】:

    由于您没有解释确切的问题,我可能只给出提示:

    1. 导出为可执行 Jar

      在 Eclipse 中,可以选择导出为 jar 文件,也可以选择导出为可执行的 jar 文件(请参阅http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-37.htm)。

    2. (我猜你使用的是 windows)尝试从控制台执行 jar 文件(类似于 java -jar )。

      在 windows 中双击 jar 文件不会打开终端窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多