Play eclipse-Add JAR file

Source: Internet
Author: User

A very important reason for personal preference Java is that a rich jar library can be used. The JAR (Java Archive) is a compressed document format in Java, based on the popular ZIP file format. Unlike zip, jar files can be used not only for compression and publishing, but also for deploying and encapsulating libraries, components, and plug-ins, and can be used directly by tools such as compilers and JVMs. In the actual development process, the spirit of "copycat" thinking, often directly using others have been developed a good jar bag, to avoid duplication of "build wheels", improve the speed of project development. This article has sorted out several ways to add jar packs to your project. Depending on where the jar is stored, there are two ways to add a jar: Add an internal jar and add an external jar.

The jars that eclipse successfully added to the project are uniformly displayed under the referenced libraries directory, as shown in the following illustration:


1. Add Internal jar

If the jar file that you want to add is already in the project directory, you can assume that the jar is part of the project, so this can be called adding an internal jar. The advantage of this is that when the project is moved to a different environment, the jar packages are moved together and there is no shortage of classes in the jar package.

To add an internal jar, first put the jar in the project. In Eclipse, select the project, right-click-> New-> folder, and create a new one called Lib to hold all the jar packages that the project uses.


When you copy the jar file to the Lib folder, F5 refreshes the project and you see the Lib folder that contains the jar package.


1.1 Add Internal Jar Method 1

Select the jar package under the Lib folder, and the right key-> build Path-> the ADD to build Path,jar package is moved from Lib to the referenced libraries directory:


1.2 Add Internal Jar Method 2

Select the item, right-click-> build Path-> Configure build path ..., the Project Properties dialog box is shown in the following illustration:


Click on the Library tab, click the "Add JARs ..." button, and in the Jar Selection dialog box, select the jar file in the project's Lib directory and click OK.


2. Add external jar

If the jar package is not in the project directory but is stored outside the project directory, it is referred to as adding an external jar. In this case, the item is moved to another environment, or the path to the jar is changed, and the jar file cannot be found incorrectly. Therefore, this approach is better suited to scenarios where the project location will not change. 2.1 Add external Jar Method 1

Select the item, right-click-> build Path-> Add External Archives ..., the action path is shown in the following illustration:


In the Jar Selection dialog box, after selecting the external jar, click Open:


2.2 Add external Jar Method 2

Select the item, right-click-> build Path-> Configure build path ..., the Project Properties dialog box is shown in the following illustration:


Click on the Library tab and click the "Add External JARs ..." button to select an external jar in the Jar selection dialog box, such as adding external jar Method 1. Reference

http://www.wikihow.com/add-jars-to-project-build-paths-in-eclipse-(Java)

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.