Why do we need to add to build path after importing the jar package? ? ?

In fact, the main step to import the jar package is add to build path. Instead of putting your jar package in the lib directory.

 

First of all, let's explain what is the role of the jar package in the lib directory?

Let's use an example first. If I have a project now, I use a jar package called hello.jar, which is stored in the root directory of my c drive. When I click add to build path, the referenced path is For: "C:/hello.jar". When I copy this project to another computer and run it. It will also search for the jar package in the root directory of the C drive of the computer, but there is no jar package in the root directory of the c drive of the computer. So at this time we should understand the purpose of the lib directory. When we copy the project to another computer, we will also copy the lib directory, and the build path is also "../lib/hello.jar", so he can find it no matter where the project is copied The corresponding jar package.

 

Finally, let's talk about the role of add to build path?

Simply putting the jar package in the lib directory has no effect, because it is not imported into the project at this time. Just like I created an image folder under the project to store pictures, I also need to write the calling path in the code when calling the picture. In the same way, when we use the jar package, we also need this kind of code, but we can define it in the properties of the project, so this step is omitted.

 

Original: https://blog.csdn.net/baidu_28149499/article/details/77991691

 

Guess you like

Origin blog.csdn.net/cherry_vicent/article/details/108071460