When you import certain packages into a java class (for example: import javax.servet.*), an error will be reported, indicating that this package does not exist. That's because the JRE System Library of the jdk we use does not contain servet_api.jar.
At this time we can download the required servlet-api.jar from the Internet or from the Tomcat lib subdirectory. So, how to import the corresponding jar package into the java project? Below we will explain the steps of
java import package
1. First, create a new folder under the project to save the jar package. Right-click on the project name, click [New] → [Floder] in sequence to open the window for creating a new folder
2. Enter the folder name [lib], Click [ok]. Jar packages imported from outside are usually stored in the lib folder
#3. Find the jar package to be imported, select the jar package you want to use with the mouse, and then hold down the left mouse button Without releasing the key, drag the jar package to the lib folder. Or copy the jar package first, then right-click on the lib folder and select copy. Open the selection box, select the default [copy files] in the pop-up selection box, and click [OK] to close. Then you can see the successfully copied jar package in the lib folder.
4. At this time, just copy the jar package to the project, but it cannot be used yet. You need to right-click on the project name and select
[Build Path]→[Configure Build Path...] in order.
5. In the opened window, select the [Libraries] page and click [add JARs...] from the button in the right column
6. In the opened window, expand the project and lib folder in order, then select the jar package just copied to the project, and click [OK] to close the window
7. In the [Libraries] page just opened, you can see the name of the jar package just introduced. Click [OK] to confirm.
8. At this time, in [Eclipse], you can find and start using this jar package.
The above is the detailed content of How to import packages in java?. For more information, please follow other related articles on the PHP Chinese website!