eclipse--about adding a user library

Source: Internet
Author: User
Tags root directory

Eclipse is the first choice for our Java Engineer Development platform, and there are many features that improve the efficiency of development, and this time we'll talk about adding a user library.

First of all, we chose the eclipse version of Eclipse Java EE IDE for Web Developers.Version:Juno Service Release 2. I am now using the Eclipse Java EE IDE on my computer, the following explanation is also based on this version, different versions of Eclipse may have subtle differences, but basically the function is similar.

We review the scenario where we use the user library: When developing a project locally, when it comes to building a framework to import multiple associated jar packages, it is common to create a user library, put the set of jar packages into a user repository, and then project directly to associate the user library, eliminating the need to import jars every time. For example, our project needs to use the spring framework, all the jar packages have 21, we generally choose some of them to meet the needs of the project, we reproduce a process of adding a user library:

1. Open the new window of libraries

2. Create a new user library

3. Add an externally associated jar package for the user library

4, add the display after the jar, here is just a description of the process of creating the user library, so only selected two jar package as an example

5. Adding user libraries to the project

6. Select User Library

7. Select the newly created user library

8, the user library added to the project effect, pay special attention to the part of the circle (the path of the jar package)

We've spent a lot of time recreating the process of creating a new user library, which is an estimate that everyone is accustomed to, but here I have two questions:

1. When adding user libraries, what files will be produced in Eclipse. or modify which file to save the user library information we added.

2, the use of User library method of the project to transplant, will not cause any impact.

Let us first answer the 2nd question: it will cause an impact, and the associated jar package will not be found when porting the project. The reason is that the user library simply directs the location of the jar package file (which I'm reminding you of in the previous image), does not copy the jar package to the workspace, and when publishing or porting the project, you need to copy the associated jar package file and re-associate it. So the general establishment of user library is only personal development convenience, in team development, there will be associated jar package synchronization problem, in fact, is not very convenient. As a general practice, if you are building a common Java project, create a Lib folder in the project root directory, copy the jar package that you need to the directory, copy the past with the porting project, and if it is a Web project, put the jar package under Web-inf/lib. In this case, there will be no associated jar packets found in the project, but it will make the project larger, but it is worthwhile to think.

Now let's look back at question 1:

When I searched for "myspring" in Eclipse's workspace (the user library name shown above), I found it in workspace\.metadata\.plugins\org.eclipse.core.runtime\. Settings\org.eclipse.jdt.core.prefs this file to find the following:

Org.eclipse.jdt.core.userlibrary.myspring=<?xml version\= "1.0" encoding\= "UTF-8"? >\r\n<userlibrary Systemlibrary\= "false" version\= "2" >\r\n\t<archive path\= "e\:/framework/spring-framework-4.0.0.m2/libs/ Spring-aop-4.0.0.m2.jar "/>\r\n\t<archive path\=" e\:/framework/spring-framework-4.0.0.m2/libs/ Spring-aspects-4.0.0.m2.jar "/>\r\n</userlibrary>\r\n

Note the added user library will leave a record in this file.

Observe this file: Org.eclipse.jdt.core.prefs is a properties type of document, we added a row of our new Myspring user library information, the information is stored in XML format, note the Archive node's Path property, this is the original When importing the path to the external jar package, the visible user library does simply direct the jar package and does not copy. When porting a project, if the new environment does not have this file under the same path, it will report an error that the jar package cannot find.

Thus:

1, the file path where the Org.eclipse.jdt.core.prefs is located (the path begins with workspace), the added user library behavior can only be valid in the specified workspace (workspace), and switching workspaces can cause the user library to be migrated.

2, the user library just declares the path of the associated jar package, when publishing the project, the associated jar package will not be published together (by default), and if the associated jar package path changes (such as I cut the jar package to another path), will also cause user library error.

I believe you in the development process, similar problems have encountered, I personally just feel that we can use the development platform to understand a little more, more in-depth, the development platform to our productivity can be larger. The above description, if discrepancies, welcome you treatise.

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.