How to run a JAR file

前端 未结 11 2339
长发绾君心
长发绾君心 2020-11-22 04:18

I created a JAR file like this:

jar cf Predit.jar *.*

I ran this JAR file by double clicking on it (it didn\'t work). So I ran it from the

11条回答
  •  醉酒成梦
    2020-11-22 04:48

    A very simple approach to create .class, .jar file.

    Executing the jar file. No need to worry too much about manifest file. Make it simple and elgant.

    Java sample Hello World Program

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }
    

    Compiling the class file

    javac HelloWorld.java
    

    Creating the jar file

    jar cvfe HelloWorld.jar HelloWorld HelloWorld.class
    

    or

    jar cvfe HelloWorld.jar HelloWorld *.class
    

    Running the jar file

     java -jar HelloWorld.jar
    

    Or

    java -cp HelloWorld.jar HelloWorld
    

提交回复
热议问题