1) Running from Command line
Since you are not running your code in a maven phase, you first need to compile the code. Remember exec:java does not automatically compile your code, you need to do that first. view plaincopy to clipboardprint?- mvn compile
Once your code is compiled, the following command runs your class
Without arguments:
view plaincopy to clipboardprint?- mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main"
With arguments:
view plaincopy to clipboardprint?- mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.args="arg0 arg1 arg2"
With runtime dependencies in the CLASSPATH:
view plaincopy to clipboardprint?- mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.classpathScope=runtime
2) Running in a phase in pom.xml
You can also run the main method in a maven phase. For example, you can run the CodeGenerator.main() method as part of the test phase. view plaincopy to clipboardprint?org.codehaus.mojo exec-maven-plugin 1.1.1 - test
java com.vineetmanohar.module.CodeGenerator arg0 arg1
To run the exec plugin with above configuration, simply run the corresponding phase. view plaincopy to clipboardprint?
- mvn test
3) Running in a profile in pom.xml
You can also run the main method in a different profile. Simply wrap the above config in the tag. view plaincopy to clipboardprint?code-generator org.codehaus.mojo exec-maven-plugin 1.1.1 - test
java com.vineetmanohar.module.CodeGenerator arg0 arg1
To call the above profile, run the following command: view plaincopy to clipboardprint?
- mvn test -Pcode-generator
Advanced options:
You can get a list of all available parameters by typing: view plaincopy to clipboardprint?- mvn exec:help -Ddetail=true -Dgoal=java
arguments (exec.arguments) The class arguments.
classpathScope (exec.classpathScope, Default: compile) Defines the scope of the classpath passed to the plugin. Set to compile, test, runtime or system depending _disibledevent=> executableDependency
If provided the ExecutableDependency identifies which of the plugin dependencies contains the executable class. This will have the affect of _disibledevent=>view plaincopy to clipboardprint?
- [ERROR] BUILD ERROR
- [INFO] ------------------------------------------------------------------------
- [INFO] Failed to configure plugin parameters for: org.codehaus.mojo:exec-maven-plugin:1.1.1
- on the command line, specify: '-Dexec.arguments=VALUE'
- Cause: Cannot assign configuration entry 'arguments' to 'class [Ljava.lang.String;' from '${exec.arguments}',
- which is of type class java.lang.String
- [INFO] ------------------------------------------------------------------------
- [INFO] Trace
- org.apache.maven.lifecycle.LifecycleExecutionException: Error configuring: org.codehaus.mojo:exec-maven-plugin.
- Reason: Unable to parse the created DOM for plugin configuration
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:588)
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:513)
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:483)
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:331)
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:292)
- at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
- at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
- at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
- at org.apache.maven.cli.MavenCli.main(MavenCli.java:301)
Solution exec.arguments was used before version 1.1 of the exec plugin, it did not support conversion of command line String to String[] array.
- If possible upgrade to 1.1 or later and use exec.args instead of exec.arguments.
- If you can't upgrade the plugin version, you can still use command line arguments with a profile and use multiple
tags associated in the pom.xml
References
- Official Maven Exec Plugin Documentation
- Tweet your builds with Maven Twitter Plugin
- The plugin ‘org.codehaus.mojo:selenium-maven-plugin’ does not exist or no valid version could be found
- Maven Cargo JBoss
- How to automate project versioning and release with Maven
- Maven Selenium
最新评论