Jar Packaging and Classpath configuration

Source: Internet
Author: User
Tags parent directory
1 Preface

When you write your own common classes, in order to facilitate their import these common classes, you can pack the class files of these common classes into a jar file and then configure it into the classpath. 2 method of jar package compression

First into the package parent directory of these classes (such as the package of these classes is net.csdn.blog.jexhen, then we should go to the directory above the Jexhen directory), and then enter the command line

JAR-CVF Test.jar *. *

Test.jar This name can be casually, as you like, also pay attention to the space between the command line, the first "*" and ". *" between the space, meaning that the folder and files are compressed into the jar package

Other parameters can be typed jar return at the command line view 3 classpath configuration Method

Put the jar path of the person into the environment variable classpath (if the Test.jar on the path is D:\test\, then we should add D:\test\test.jar in the environment variable classpath)

Then we can import our own common classes in the source code we write, assuming that my jar package class has a test class, so I can import the class like this:

Import Net.csdn.blog.jexhen.Test;

public class Testjar {public
    static void Main (string[] args) {
        test test = new test ();
    }
}






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.