Create a Maven Project in Eclipse and run .jar file

Create a Maven Project in Eclipse and run .jar file

  • Go to the File option => In the drop-down menu, select New => select Maven Project

Article content

  • Select desired path => click next

Article content

  • Select latest org.apache.maven.archetypes from catalogs Group id and maven-archetype-quickstart from Artifact id => click next

Article content

  • Enter the Group ID with any name like com.proj and Artifact ID as demoMavenProj => click finish

Article content

  • Eclipse console might ask for confirmation like below => type Y => hit enter then project will be created, you will see BUILD SUCCESS in console.

Article content
Article content

  • Project has been created, now open pom.xml, You will see all the basic information, such as the Artifact ID, Group ID, etc. You will also see the junit dependencies for test cases.

Article content

  • you will see AppTest.java a default test case written in JUnit.

Article content

  • you will also see default class as App.java which was create as part of initial boilerplate.

Article content

  • To create a .jar file, select Maven build => type any goal name like package => click run

Article content
Article content

  • You might error in console like Source option 7 is no longer supported. Use 8 or later. OR Target option 7 is no longer supported. Use 8 or later. and BUILD FAILURE, update version number in pom.xml and retry

Article content

  • Do project refresh and you will see demoMavenProj-0.0.1-SNAPSHOT.jar file in target folder

Article content

  • Go to folder and hit cmd, and execute .jar file using java -jar demoMavenProj-0.0.1-SNAPSHOT.jar

Article content
Article content

  • You might see error like below and open archive like below => META-INF => open MANIFEST.MF => add Main-Class: com.proj.demoMavenProj.App

Article content
Article content
Article content

  • now, run command java -jar demoMavenProj-0.0.1-SNAPSHOT.jar in cmd.

Article content

Now a days I am learning Java so credit also goes to Navin Reddy Hyder Abbas All the concepts have been explained in a clear and engaging manner, I appreciate your teaching style.

Course Link: https://courses.telusko.com/learn/Live-Java-Course

My git repo for java learning https://github.com/anu3dev/learningJava

Article content



To view or add a comment, sign in

More articles by Anurag K.

Explore content categories