【问题标题】:How do I Make this code run in CMD when i click the jar file [duplicate]单击jar文件时如何使此代码在CMD中运行[重复]
【发布时间】:2019-03-09 09:12:22
【问题描述】:
package com.company;

public class Main {

    public static void main(String[] args) {
        int count = 0;
        do {
            count = count + 1;

            if (count == 500000000) {
                break;
            }

            System.out.print(count);
            System.out.print("\n");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }while(true);
    }
}

只是希望它从 jar 文件在控制台中运行,而不是在后台运行

【问题讨论】:

    标签: java runtime


    【解决方案1】:

    1) 创建一个名为 Main.mf 的文本文件,其中包含以下两行:

    清单版本:1.0

    主类:主要

    2)然后通过键入以下内容创建存档:

         jar cmf Main.mf Main.jar Main.class Main.java
    

    3) 然后使用运行它

         java -jar Main.jar
    

    【讨论】:

    猜你喜欢
    • 2013-09-09
    • 2012-09-24
    • 1970-01-01
    • 2021-12-12
    • 2020-08-27
    • 2010-09-16
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多