How to make and auto run /executable jar with dependencies?


To make auto run/executable jar by eclipse follow below steps.

  • Create Java Project in Eclipse by following these steps as below New -> Project ->Java Project -> Click Next
  • Type Project Name as JavaAutoRunExample -> click on Finish button.
  • Expend project JavaAutoRunExample on left panel and create package as com.facingissuesonit.test
  • Create below class TestHelloWorld inside package com.facingissuesonit.test
    package com.facingissuesonit.test;
    
    public class TestHelloWorld {
    
    	public static void main(String[] args) {
    		System.out.println("Inside Package facing Issues on IT");
    		System.out.println("Test Hello World !!");
    	}
    
    }
    

Now your Project Structure will looks like as below.

Auto Run Jar Project

Now in below steps will show  to convert this project as auto run/executable jar where entry point would be main method of class TestHelloWorld.

Note : If in your project having multiple classes having main method you can decide one entry point by below steps.

  • Build and Test you project so that there would be any compile and runtime issues. Select class TestHelloWord -> Right click -> Run As -> Java Application. You will get below console output.
    Inside Package facing Issues on IT
    Test Hello World !!
    
  • Right Click on JavaAutoRunExample ->export ->Java->Runnable Jar File -> Click on Next.

Auto run Jar Selection

  • Select Launch Configuration as TestHelloWorld and export destination where want to keep this auto run/executable jar and dependency jar options as below.Auto Run lanunch Selection
  • Now your auto run/executable jar is ready . For executing it go to command promt (CMD) and select location for file and use below command

java -jar AutoRunTest.jar

C:\Users>cd C:\Users\facingissuesonit\Documents

C:\Users\facingissuesonit\Documents>java -jar AutoRunTest.jar
Inside Package facing Issues on IT
Test Hello World !!

 

 

Hope this blog was helpful for you.

Leave you feedback to enhance more on this topic so that make it more helpful for others.

About Saurabh Gupta

My Name is Saurabh Gupta, I have approx. 10 Year of experience in Information Technology World manly in Java/J2EE. During this time I have worked with multiple organization with different client, so many technology, frameworks etc.
This entry was posted in Java and tagged , , , , , , . Bookmark the permalink.

One Response to How to make and auto run /executable jar with dependencies?

  1. Pingback: Elasticsearch REST Index Manager Auto Client for CRUD | Facing Issues On IT

Comments are closed.