How to put a jar in classpath in Eclipse?

The question:

Hi I am n00b in classpath and Ant. While reading the tutorial of GCM for Android I came across a line

Step 1: Copy the gcm.jar file into your application classpath

To write your Android application, first copy the gcm.jar file from
the SDK’s gcm-client/dist directory to your application classpath.

I got the gcm.jar from the dist folder. Now how do I put it into my classpath using Eclipse(I think that would be easier)? And where would I make changes if I didnt have Eclipse?


The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

As of rev 17 of the Android Developer Tools, the correct way to add a library jar when.using the tools and Eclipse is to create a directory called libs on the same level as your src and assets directories and then drop the jar in there. Nothing else.required, the tools take care of all the rest for you automatically.

Method 2

Right click on the project in which you want to put jar file. A window will open like this

enter image description here

Click on the AddExternal Jars there you can give the path to that jar file

Method 3

First copy your jar file and paste into you Android project’s libs folder.

Now right click on newly added (Pasted) jar file and select option

Build Path -> Add to build path

Now you added jar file will get displayed under Referenced Libraries. Again right click on it and select option

Build Path -> Configure Build path

A new window will get appeared.
Select Java Build Path from left menu panel and then select Order and export
Enable check on added jar file.

Now run your project.

More details @

Method 4

Right click your project in eclipse, build path -> add external jars.

Method 5

In your Android Developer Tools , From the SDK Manager, install Extras > Google Cloud Messaging for Android Library . After the installation is complete restart your SDK.Then navigate to sdkextrasgooglegcmgcm-clientdist .
there will be your gcm.jar file.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment