FreeKB - Eclipse Create a Java Archive (JAR) file
Eclipse - Create a Java Archive (JAR) file

Create a new project in Eclipse

In Eclipse, select  File > New > Java Project. Give your project a name, such as Sample and select Finish. In this example, a project called Sample is created.


Create a package

In the left panel of Eclipse, expand your project. Right-click on the src folder and select New > Package. Give your package a name and select Finish. In this example, a package named com.sample.main is created.


Create a class

Right-click on the package, and select New Class. 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

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


View the JAR

Using the jar command, you can view the contents of the JAR file. 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 2f170 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |