Monday 10 June 2019

Java: How to create a jar file


‘jar -cvf’ command is used to create a jar file.

Create Employee.java file and follow below directory structure.
$tree
.
└── com
    └── sample
        └── demoapp
            └── model
                └── Employee.java


Employee.java
package com.sample.demoapp.model;

public class Employee {

 public String toString() {
  return "Represent Employee Information";
 }
}


Compile Employee.java.
$javac com/sample/demoapp/model/Employee.java 
$
$tree
.
└── com
    └── sample
        └── demoapp
            └── model
                ├── Employee.class
                └── Employee.java

Create ‘demoapp.jar’ file by executing below command.

jar -cvf demoapp.jar *
$jar -cvf demoapp.jar *
added manifest
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/sample/(in = 0) (out= 0)(stored 0%)
adding: com/sample/demoapp/(in = 0) (out= 0)(stored 0%)
adding: com/sample/demoapp/model/(in = 0) (out= 0)(stored 0%)
adding: com/sample/demoapp/model/Employee.class(in = 326) (out= 244)(deflated 25%)
adding: com/sample/demoapp/model/Employee.java(in = 137) (out= 112)(deflated 18%)
$
$tree
.
├── com
│   └── sample
│       └── demoapp
│           └── model
│               ├── Employee.class
│               └── Employee.java
└── demoapp.jar


You may like


No comments:

Post a Comment