How to create a Java Archive (JAR) file using Eclipse

Home > Search > How-to

Create a new project in Eclipse

  1. In Eclipse, select  File > New > Java Project.
  2. Give your project a name, such as Sample and select Finish.

In this example, a project called Sample is created.


Create a package

  1. In the left panel of Eclipse, expand your project.
  2. Right-click on the src folder and select New > Package.
  3. Give your package a name and select Finish.

In this example, a package named com.sample.main is created.


Create a class

  1. Right-click on the package, and select New Class.
  2. Give the class a name, and select Finish.

In this example, a class named People is created.


In the newly created class, add the following markup.

package com.sample.main;

public class People {
	public String name = "John Doe";

	public String getName(){
		return name;


Create the JAR

  1. Right-click on your project and select Export.
  2. Select JAR file and select Next.
  3. Select Browse and select a location on your local PC.
  4. Select Finish.


View the JAR

In this example, the JAR will contain the People.class in the com/sample/main/ package.



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.