About JAR file

What is jar file
JAR stands for Java ARchive. It is a file format based on the popular ZIP file format and is used for aggregating many files into one. JAR can be used as a general archiving tool that can combine android components like class files, manifest.xml, images etc. The JAR format also supports compression, which reduces the size of the file and improves download time still further.

Extract jar file from cmd
open cmd prompt, goto directory where you have put your jar file.
For example, I put gcm-src.jar file in d:\New folder

Type this:
D:\New folder\jar xf gcm-src.jar

You can see the the content of jar file in that folder (D:\New folder)

Create jar file
First you collect files that you want to put in your jar file. Create one folder, put all files in it. Then open cmd prompt, goto that new folder directory. Use the command jar cvf <jar-name> <files>

For example:
D:\New folder\jar cvf class.jar Log.java LogNode.java LogView.java LogWraper.java

Here class.jar is jar file name
LogNode.java, LogView.java, LogWraper.java are java files.

If you want to see the content of tha jar file, use this command
jar tf <jar-name>

For example:
D:\New folder\jar tf class.jar

Output will be like this:
META-INF/
META-INF/MANIFEST.MF
LogNode.java
LogView.java
LogWraper.java

Javap command
The javap command disassembles one or more class files. Its output depends on the options used. If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it.

Syntax: javap class-file

For example, compile the following class declaration:

javap FetchActivity.class

Output:
Compiled from "FetchActivity.java"
public class com.example.sqlite.FetchActivity{
  android.content.Context con;
  com.example.sqlite.GetterSetter gs;
  public com.example.sqlite.FetchActivity(android.content.Context, com.example.sqlitw.GetterSetter);
   public void insert();
   public void update();
   public void delete();
}

Comments

Popular posts from this blog

MVC Architecture in Android

Get Current Location using GPS/Network Provider

SQLiteDatabase (Without SqliteOpenHelper class)