简体   繁体   中英

Regarding Adding libraries in Eclipse

In eclipse, I am trying to add some libraries. I choose "build path->configure build path->libraries". The right column of the "java build path" window gives me several options: Add JARS, Add External JARS, and Add Library.

It seems to me that I should choose "Add Library", but what do the other two work for, "Add JARS" and "Add External JARS". What are the differences among these three options?

Add Jars is for internal Jars - ie jars from your project workspace. Add external Jars is for jars in a different directory on your hard drive - eg ones you downloaded or from a diff workspace. This is the same as "Add Library" really, except that a library is a handy label for external jars that you add regularly. See http://www.javaprogrammingforums.com/java-code-snippets-tutorials/6536-javatip-dec-18-2010-eclipse-user-libraries.html for an example of how to add.

Add Library allows you to add a library defined in your Eclipse coniguration. If you check a project into a source control system and somebody checks it out, it would compile only if that developer has corresponding Eclipse libraries configured.

Add JARs allows to add jar files that are located in a subdirectory of your project's directory, usually named lib. You would check these jars into your source control system with your project and everyone who checks the project out would have these libraries.

Add External JARs is the least useful approach. It adds dependencies to the jar files of libraries located elsewhere on your computer and it hardcodes the pathnames of these files. If you check the project into a source control system and somebody checks it out, it would build only if they have the same libraries in the exact same places. Forget about teams using a mix of Windows, Mac and Linux workstations!

'Add JARS' allows you to add JARs that are resident in the workspace to the project build path.

'Add External JARS', well, allows you to add JARs that are resident outside the workspace. You can add JARs that are inside the workspace, but the above option is meant to perform that.

Libraries, on the other hand, refer to the various predefined libraries in Eclipse. A library is usually an organized collection of JARs. It could refer to:

  • the JRE System library, consisting of JARs in the JDK/JRE used for building the project
  • a Java EE Server Runtime, made available through an installation of a WTP adapter for a server
  • User Libraries (that can be created by the user)
  • JDBC Connectivity Driver Definitions
  • Libraries that ship with Eclipse, like JUnit 3.x, 4.x.

Adding a Library adds all the entries specified in the library definition to the build path.

  • Add Jars Lets you point to jars contained within your project.

  • Add External Jars Lets you point to jars anywhere on the file system.

  • Add Library Lets you point to a set of jars you have pre defined.

Have a look at this eclipse documentation - especially the Libraries tab section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM