How to Generate JWT token from Command Line (JAVA)

January 20, 2017


Installed ZAPI CLOUD and wondering how to generate JWT token without using IDE


There are various ways to generate JWT Token. Java samples are available in our knowledge base. Please follow the below steps to create a JWT token using Java sample from command line without having any IDE like eclipse.


Confirm Java8 is installed and JAVA_PATH set. Check Java version installed on your machine using below command.

G:\ZAPI_CLoud>java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode)


Download the jwt-generator.jar and save to the same location say G:\ZAPI_CLoud.

Edit the parameter values for accessKey,secretKey,userName and API in the file matching your requirement.

  1. Open command prompt.
  2. Change directory to the location of your java file downloaded above G:\ZAPI_CLoud
  3. Compile your java file adding the dependency jar jwt-generator.jar to classpath as shown below:
    G:\ZAPI_CLoud>javac -cp ".;jwt-generator.jar"
  4. Now, run the class file generated using the below command
    G:\ZAPI_CLoud>java sampleJwtGenerator
  5. You will get the Final API and JWT token as output

  6. Use the Final API and JWT Token created above to make API requests.