Tag Archives: dependency

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.

How to add 3rd Party/Custom/External Jars to Maven Project?


In below steps will show about to add 3rd party/custom/external Jars in local repository for use in our project builds because these jars doesn’t exist in Maven public repository and required to build project.

Pre-Requisite

To add these jars we can use below command to load in local repository (.m2/repository)

mvn install:install-file -Dfile= -DgroupId=
-DartifactId= -Dversion= -Dpackaging=

Example : Oracle is 3rd party and it’s jars are available in maven public repository. We can use below command to store in maven local repository and make entry in pom.xml to use it.

mvn install:install-file -Dfile=C:\\Workspace\\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

pom.xml entry for above oracle jar


	com.oracle
	ojdbc6
	11.2.0