Myeclipse import third-party jar

Source: Internet
Author: User
Myeclipse import third-party jar

10:38:17 | category:

Java
| Label: | large font size, small/medium subscription

Using eclipse to develop Java SE will inevitably require the introduction of third-party jar or calss files. Here we will explain how to introduce third-party jar or calss files in eclipse.

Let's first look at the location of the jar introduced in the Eclipse project:

As shown in, each project contains a JRE System Library [JavaSE-1.6], the system library, and the JavaSE-1.6 in the brackets is the local JDK version number.
The system library contains many jar files, which are located in the java_home (JDK installation directory) \ JRE \ Lib and java_home \ JRE \ Lib \ ext folders in the environment variables. The jar files in the system library can be used directly without any settings.
Eclipse can contain one or more reference libraries as extension class libraries in each project.

1. Introduce the JAR file in the Workspace

To build a javase development environment connected to mssql2005, we need to introduce a sqljdbc. Jar. When we try to copy the JAR file paste to reference libraries, we get the following prompt:

Copy the JAR file directly to the project:

Although sqljdbc. jar can be seen, we cannot use it. We also need to build a Java build path. Right-click the project name and choose Properties> JAVA build path> libraries tab to open the following interface.

* You can also right-click the project name and choose build path> Configure build path> libraries tab.

Select Add jars...

Select to copy the sqljdbc. jar file to the project. Click OK. Sqljdbc. jar is introduced into the project.

In the project, view the path of sqljdbc. jar in reference libraries. The reference is copied to sqljdbc. jar in the project.

* When the project is opened, the jar files in the working environment can be referenced by other projects in the same way. However, once the project is deleted or closed, other jar files referenced in the project cannot be used. Therefore, this reference method is suitable for independent project references.

2. introduce external jar

You can put all external jar files in a folder, such as F:/jars/sqljdbc. jar, also open the libraries tab, select Add external jars ..., select F:/jars/sqljdbc. jar, and then the jar will be introduced into the project.

* The imported jar files are stored on the local computer. Copy jar files when copying projects.

3. Introduce user Libraries

In eclipse, -- select Window menu -- preferences -- Java -- Build path -- User Libraries

Select the new button on the right of the panel -- User library name -- enter sqljdbc -- Click OK to confirm, the empty user library is defined.

* The check box before the system library below does not affect the usage of our program, but it only applies to loading the driver using different classloaders.

In this case, no jar files are used in the user library. Click Add jars... on the right panel and select the JAR file to be added. After you select open, the JAR file will be added to the user library. Click OK. A user library containing the JAR file is defined.

Introduce user library in the project

Right-click the project name and choose Properties -- select Java build path -- select libraries tab -- select Add library... on the right -- Select User Library

Click Next to go to the next step, select the newly created sqljdbc user library, and click Finish to complete the import.

* The imported jar package also depends on the current environment. When copying a project, remember to copy the jar package at the same time. Of course, you can put the JAR file under the project root directory to copy the project to other development machines.

4. Introduce jar in Environment Variables

In eclipse, -- select Window menu -- preferences -- Java -- Build path -- calsspath Variables

Click the new button on the right and enter the name in the name input box. to display the jar imported through calsspath variables, we recommend that you name it sqljdbc_home. The path input box provides two options, if there is only one jar file, you can select it through the file button. Multiple jar files exist in one directory. You can use floder to select the directory where the JAR file is located. Click OK. The calsspath variables containing the JAR file is defined.

Introduce calsspath variables in the project.

Right-click the project name and choose Properties -- select Java build path -- select libraries tab -- select Add variable... on the right -- select the newly added sqljdbc_home.

Because sqljdbc_home references the directory file where the JAR file is located, you also need to click the extend button in the upper right corner to select the JAR file. Click OK to introduce the selected JAR file.

5. Introduce the calss File

Right-click the project name and choose Properties> JAVA build path> libraries tab> Add class folder to import and copy the class file to the project.

Right-click the project name and choose Properties> JAVA build path> libraries tab> Add external class folder to introduce the external class folder.

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.