EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Maven exec plugin

Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML
Home Software Development Software Development Tutorials Maven Tutorial Maven exec plugin

Maven exec plugin

Introduction to Maven exec plugin

It is used to execute java and system code from the maven command, basically, there are two goals i.e. exec: exec and exec: java. The first goal is exec: exec which was used to execute any of the programs in a different process, the second goal is exec: java which was used to execute the java program on the same server. To use any maven exec plugin in java first we need to add the same into the pom.xml file. Without adding the exec plugin into the pom.xml file we cannot use this in our project.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

How does it work?

  • Basically, it has two goals defined first one is exec: exec, and the second one is exec: java.
  • The first goal is used to execute any code into the different processes. The second goal is used to run java code on the same server.
  • Below is the version available for general use is as follows.
  1. Version 1.0
  2. Version 1.0.1
  3. Version 1.0.2
  4. Version 1.1
  5. Version 1.1.1
  6. Version 1.2
  7. Version 1.2.1
  8. Version 1.3
  9. Version 1.3.1
  10. Version 1.3.2
  11. Version 1.4.0
  12. Version 1.5.0
  13. Version 1.6.0
  14. Version 3.0.0
  • To execute the java code using the maven exec plugin we need to configure the same into the build section of the pom.xml file.
  • We need to add the below configuration in the pom.xml file to use the maven exec plugin in our project.

<plugin>  -- Start of plugin section
<groupId> /* Start of groupId section */ name of groupid </groupId> -- end of groupid section.
<artifactId> /* Start of artifactId section */  exec-maven-plugin</artifactId> -- end of artifactId section.
<version> /* Start of version section */ version number </version> -- end of version section.
<configuration>
<mainClass> /* Start of mainClass section */ main class name </mainClass> -- end of mainClass section.
</configuration> -- -- end of configuration section.
</plugin>  -- end of plugin section.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • The first section contains the plugin, the execution of maven exec starts from the plugin section. We need to end each section which was we have started.
  • The second section contains the groupid, this is nothing but the name of groupid which was used in maven exec plugin.
  • The third section contains the artifactid, this is nothing but the name of exec plugin which was used in the configuration of the maven exec plugin.
  • The fourth section contains the version, this is nothing but the actual version number of exec plugin which was used in the configuration of the maven exec plugin.
  • The fifth section contains the main class, this is nothing but the name of the main class of the exec plugin which was used in the configuration of maven exec plugin.
  • Below is the important section which was we need to be used at the time of configuration of the maven exec plugin.
  1. Groupid
  2. ArtifactId
  3. Version
  4. Main class
  • To configure it in our project we need to follow the below steps are as follows.
  • Add this plugin configuration to the pom.xml file.
  • Run the Maven build by using the exec: java goal.
  • Add the configuration into the pom.xml file is very important. Without adding the configuration into the pom.xml file we cannot build the maven exec plugin.
  • The mainClass element within the configuration is the most significant thing to notice. In that section, we have to define the class of java which was run by the exec: java goal.
  • In the plugin configuration, we can explicitly provide all of the necessary execution details. Also we can supply all information or some information using system properties, depending on our use case.
  • Below are the optional parameter which was used while configuring it are as follows.
  1. addOutputToClasspath – The type of this parameter is boolean.
  2. addResourceToClasspath – The type of this parameter is boolean.
  3. arguments – The type of this parameter is the list.
  4. async – The type of this parameter is boolean.
  5. asyncDestroyOnShutDown – The type of this parameter is boolean.
  6. classpathScope – The type of this parameter is string.
  7. commandlineArgs – The type of this parameter is string.
  8. environemntScript – The type of this parameter is file.
  9. environemntVariables – The type of this parameter is map.
  10. executable – The type of this parameter is string.
  11. executableDependency – The type of this parameter is executable dependency.
  12. longClasspath – The type of this parameter is boolean.
  13. longModulepath – The type of this parameter is boolean.
  14. outputFile – The type of this parameter is file.
  15. quietLogs – The type of this parameter is boolean.
  16. skip – The type of this parameter is boolean.
  17. sourceRoot – The type of this parameter is file.

Examples

Below is the example is as follows.

Example #1 – With default parameter

Code:

<plugin>  -- Start of plugin section
<groupId> /* Start of groupId section */ org.codehaus.mojo</groupId> -- end of groupid section.
<artifactId> /* Start of artifactId section */  exec-maven-plugin</artifactId> -- end of artifactId section.
<version> /* Start of version section */ 1.6.0 </version> -- end of version section.
<configuration>
<mainClass> /* Start of mainClass section */ com.journaldev.maven.utils.BuildInfo</mainClass> -- end of mainClass section.
</configuration> -- -- end of configuration section.
</plugin>  -- end of plugin section.

Example 1-1

# mvn exec:java

Maven exec plugin Example 1-2

Example #2 – With optional parameter

Code:

<plugin>  -- Start of plugin section
<groupId> /* Start of groupId section */ org.codehaus.mojo</groupId> -- end of groupid section.
<artifactId> /* Start of artifactId section */  exec-maven-plugin</artifactId> -- end of artifactId section.
<version> /* Start of version section */ 1.6.0 </version> -- end of version section.
<configuration>
<executions>
<execution>
</configuration> -- -- end of configuration section.
</execution>
</executions>
</plugin>  -- end of plugin section.

Example 2-1

# mvn exec:java

Example 2-2

Conclusion

It is very useful and important to execute java and system code from the maven command. There are two goals is used i.e. exec: exec and exec: java. To use it in the project we need to configure the same in pom.xml file.

Recommended Articles

This is a guide to Maven exec plugin. Here we discuss How does the Maven exec plugin work along with the examples and outputs. You may also have a look at the following articles to learn more –

  1. Maven Deploy
  2. Maven Eclipse Plugin
  3. Maven Repository Spring
  4. Maven POM File
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Maven Training (4 Courses, 6 Projects) Learn More