# JAR File in Java

A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources.

**Maven dependency to create Uber Jar**

```xml
<build> 
	<plugins> 
		<plugin> 
			<groupId>org.apache.maven.plugins</groupId> 
			<artifactId>maven-assembly-plugin</artifactId> 
			<executions> 
				<execution> 
					<phase>package</phase> 
					<goals> 
						<goal>single</goal> 
					</goals> 
					<configuration> 
						<archive> 
							<manifest> 
								<mainClass>${com.npntraining.SimpleProducer}</mainClass> 
							</manifest> 
						</archive> 
						<descriptorRefs> 
							<descriptorRef>jar-with-dependencies</descriptorRef> 
						</descriptorRefs> 
					</configuration> 
				</execution> 
			</executions> 
		</plugin> 
	</plugins> 
</build>
```

**Viewing the Contents of a JAR File**

The basic format of the command for viewing the contents of a JAR file is:

```plaintext
jar tf jar-file
```

Let's look at the options and arguments used in this command:

* The t option indicates that you want to view the *table* of contents of the JAR file.
    
* The f option indicates that the JAR file whose contents are to be viewed is specified on the command line.
    
* The jar-file argument is the path and name of the JAR file whose contents you want to view.
    

The t and f options can appear in either order, but there must not be any space between them. This command will display the JAR file's table of contents to stdout. You can optionally add the verbose option, v, to produce additional information about file sizes and last-modified dates in the output.

**Extracting the contents of a JAR File**

The basic command to use for extracting the contents of a JAR file is:

```plaintext
jar xf jar-file [archived-file(s)]
```

The basic command to use for extracting the contents of a JAR file is:

> That’s it… Hope you liked this article. **Happy Learning:).**
> 
> Feel free to ask your doubts in the comments.
