Android reference jar package

Source: Internet
Author: User

First, let's get a basic idea. In eclips, right-click the project name and choose build path> contigure bud path> JAVA build path. There are several options.
Add external jars = add external project packages
Add jars = add project packages
Add library = Add a library
Add class folder = Add a class folder

The following describes the user libraries in the Add library.
To add a user library, follow these steps:
1. Right-click the project and choose build path> Add libraries...
2. Select User library-> next
3. Click the user library button.
4. Click "new ".
5. Enter the library name (I want to import the jar package of struts 2.1.6 and the jar package of JDBC. For convenience of memory, you can use struts 2.1.6 library, for example)
6. Click OK.
7. Select the user library and click Add jars.
8. Find the corresponding jar package and click OK.
 
Adding User liberary to eclipse only takes effect in eclipse, that is, only eclipse knows where the referenced classes are put, but if you want the web project to start normally, you need to tell Tomcat and other containers, where is your jar package (in the lib directory, the container will know ). Therefore, in this case, if you add a user library to eclipse for debugging and do not add the user library, the import class cannot be found in eclipse, and the red X number will appear, if you do not place the jar package in the user Library Under lib and the introduced class cannot be found for the capacity, an error is reported.
The differences between add jar and add external jars and user libraries in add library are:
Use the jar package added by "add jar" and "add external jars"ProgramIs packaged into the final program. The jar package added through "User libraries" is not.

About the role of jar package build path:
The jar package cannot be anywhere. Whether it is Java application or Java Web application.
The Java VM decides how to load the class according to the Java classloader (Class Loader:
We put the jar package under classpath because the classpath classloader exists.
We can not specify some jar packages in classpath, but it can also be used in Java programs.
That is because the parent class loader with classpath classloader is responsible for loading. For example, JRE \ Lib \ *. Jar under the JRD directory
The reason why we put the jar package into the Lib folder under webroot and can be used in our program is that the container implements its own classloader. (The web middleware server class loading mechanism is different from the three default loaders provided by Sun .)
Therefore, whether the jar can be loaded or where the jar is loaded depends on classloader.

In Android, some public resources can be shared and encapsulated into jar packages. Android resources such as activity can be protected, but res and androidmanifest cannot be added. XML, so images and other resources need to be referenced in assert. Note that * .9.png needs to be processed by the APPT tool. You can call the command line to process it, if you are a little lazy, output an APK, and then pull out the image from the package.

1, export Library
1.1 prepare source code
1.1.1 create an android Project
1.1.2 create source code, and fix all bug
1.1.3 remove androidmanifest. xml
1.1.4 Remove Res/drawable/icon.png
1.2 export Library
1.2.1 On package explorer of Eclipse, right-click created Project, and select Export
1.2.2 select Jave-> JAR file, then press \ "next \"
1.2.3 select resources to export, then press \ "next \"
1.2.4 press \ "next \"
1.2.5 press \ "finish \"
Then the library is created.

In the project of the referenced package, you must add the corresponding activity, service, and other component information in androidmanifest. xml. Add external jar or add library, introduce jar.

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.