Java Package/Command line run Jar (command line for program testing)

Source: Internet
Author: User

1      Public classtesttmp {2          Public Static voidMain (string[] args) {3            //TODO auto-generated Method Stub4              for(inti=0;i<args.length;i++){5System.out.println (i+ "=" +args[i]);6             }7         }8     } 9 Ten  Public classtesttmp { One      Public Static voidMain (string[] args) { A         //TODO auto-generated Method Stub -           for(inti=0;i<args.length;i++){  -System.out.println (i+ "=" +Args[i]);  the         }  -     } -}

Note: The class is created under the default package path;

2. Compiling: Javac Testtmp.java

3. Packing: Jar CVF Test.jar Testtmp.java

4, Update MANIFEST.MF content, add a line main-class: (space) Testtmp.java pay attention to enter,

Unzip Test.jar edit MANIFEST.MF, then compress.

5, Jar UMF MANIFEST. MF Test.jar (update manifest.mf to Test.jar file, you must guarantee two files in the same directory)


6. Test Result: Java code

    1    0 1      d:\    0 1    1 2

D:\>java-jar Testtmp.jar = 1d:\>java-jar Testtmp.jar 1 20 = 11 = 2

Note: If a run exception occurs, it is possible that the Java version of the runtime differs from the compiled Java version, modifying the path of the environment variable;

7. Special Circumstances:

If you need to reference some jar packages, here's how:

Add a line to the MANIFEST.MF, the keyword is class-path,

Format: Class-path: (space) Class1.jar (space) Class2.jar (space) Class3.jar

8. FAQ:

Http://hi.baidu.com/xffys/blog/item/d3bd2c4e92b23fc0d0c86a0b.html

http://hufeng.iteye.com/blog/574339

Java Package/Command line run Jar (command line for program testing)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.