How to Import a Jar in Eclipse

How to import a jar in Eclipse?

You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here.

Sample Image

The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.

how to import source code into Eclipse from a jar file?

Create a directory named "helloworld" and unpack the JAR into that directory:

mkdir helloworld
cd helloworld
jar xvf ../helloworld.jar

You can then create a project from existing sources and start operating on that. I don't think Eclipse will let you create a project and change files directly in the JAR.

Import project (jar) into Eclipse

I have managed it this way:
New Java Project -> Java settings -> Source -> Link source (Source folder). There I added my decompiled jar and it was imported correctly :)

How to edit .java files imported in Eclipse from a .jar file

You need to select the Export Java source files and resources option while creating the jar file and then your Java files will be available on importing the project from the jar file.

Sample Image

How to use a class from JAR in eclipse

In eclipse, right click on a project->Propeties->Java Build Path->Add External JARs (Add JARs if the jar is inside the project's folder) and then choose your jar file.
From now you can use the inner classes of the jars you added. Eclipse will import them when you'll start using them.



Related Topics



Leave a reply



Submit