If you just created a Maven project of package type jar and wondering how to run the jar from Maven command without deploying it to Tomcat or executing the jar using run time then you simply add the below plugin code that is highlighted in your under your pom.xml build -> plugins tag,
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>code2care</groupId>
<artifactId>csvexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>csvexample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>code2care.csvexample.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Note: the mainClass tag should contain the package to your main class.
Now to run the code in eclipse, all you need to do is under your maven configuration under goal ass exec:java (or clean build exec:java)
Run Maven Project using Eclipse Run Configuration
Output:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< code2care:csvexample >------------------------
[INFO] Building csvexample 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ csvexample ---
Hello World!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.624 s
[INFO] Finished at: 2020-11-06T22:37:38+05:30
[INFO] ------------------------------------------------------------------------
More Posts related to Eclipse,
- Enable Spellcheck in eclipse workspace
- List of Eclipse versions and future releases (2020-09)
- INVALID FILE NAME: MUST CONTAIN ONLY [a-z0-9_.] Android Eclipse Error
- How to enable line numbers in Eclipse IDE
- How to Save Eclipse console logs in external log file
- How to Change Eclipse Default Web Browser
- Enable Eclipse dark mode
- Add imports in eclipse shortcut key combinations
- Eclipse version 32-bit or 64-bit check
- [Eclipse] Enable or Disable print margin line
- Eclipse Error : The Eclipse executable launcher was unable to locate its companion shared library.
- Eclipse: Updating Maven Project. Unsupported IClasspathEntry kind=4
- eclipse maven m2e : Cannot complete the install
- Eclipse : This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
- Failed to load the JNI shared library jvm.dll
- [Eclipse] Syntax error, annotations are only available if source level is 1.5 or greater
- How to use Content Assist in Eclipse IDE
- How to Word wrap eclipse console logs width
- Eclipse : Workspace was written with an older version of the product and will be updated
- List of Code Snippets/Templates to Eclipse IDE
More Posts:
- Disable Fading Edges Scroll Effect Android Views - Android
- Android : Class file collision: A resource exists with a different case - Android
- Error: Can not find the tag library descriptor for "struts-tags" - Java
- [Java Threads] Should we extend Thread Class or implement Runnable interface - Java
- Android : Unable to load VM from snapshot : Mac OS X Error - Android
- Sublime Add text at start and end of each line - Sublime
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error - Android
- INSTALL_FAILED_INSUFFICIENT_STORAGE Error Android Emulator - Android
- Change Android EditText Cursor Height - Android
- Align left align text in Bootstrap - Bootstrap
- Android Studio : Implement abstract methods shortcut - Android-Studio
- Android Studio Ctrl Shift o auto import not working - Android
- Detect swipes on Android Activity - Android
- Facebook | Error : Sorry, something went wrong We're working on it and we'll get it fixed as soon as we can - Facebook
- How to copy Chrome alert popup text to clipboard - Chrome