Maven-exec-plugin throws an exception for no apparent reason

I will introduce the following in a Windows shell in a Maven root project that contains a class with

public static void main (String [] args)

which I would like to run.

mvn exec: java -Dexec.mainclass = "com.spp.config.main.SqlGeneratorHarness" -e

The class exists and is compiled in this package (i.e. target / classes / com / spp / config / main / SqlGeneratorHarness.class).

I see...

+ Error stacktraces are turned on. [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'exec'. [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Invalid task '.mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal [INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.BuildFailureException: Invalid task' .mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1830) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Tue Sep 27 14:33:52 PDT 2011 [INFO] Final Memory: 3M/122M [INFO] ------------------------------------------------------------------------ 

I tried options like

mvn exec: exec -Dexec.executable = "java" [...]

and

mvn org.codehaus.mojo: exec-maven-plugin: 1.2.1: java [...]

to no avail. What gives?

I am running Maven 2.2.1, Java JDK 1.6.0_27 on a 64-bit version of Windows 7 Enterprise.

A snippet from my pom.xml for the exec-maven plugin ...

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>${exec-maven-plugin.version}</version> </plugin> 

where the version is installed in <properties>

+4
source share
3 answers

So ... reviewing this ... if you use Windows PowerShell, you will get the exception that I originally reported. If, however, you are using cmd.exe, then you should be able to run the class using the command I sent (with or without wrapping double quotes).

+15
source

Something very basic is going wrong there. Try losing quotes. They are not needed there. Actually, try starting with something simpler, like

 mvn -e exec:java -Dexec.mainClass=foo 

This should give you the error "An exception occurred while the Java class was being executed. Foo", and the main reason should be a ClassNotFoundException:

 Caused by: java.lang.ClassNotFoundException: foo at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) 

Enter it yourself. Do not copy or paste the command from another location.

0
source

Just a quick checklist:

  • Rename the ~/.m2 folder and run mvn exec:java ... again, and let Maven download everything from the center again.
  • Make sure your exec plugin is downloaded from the center. (Make sure your local repository contains the same files as the central one .)
  • Look for the suspicious repository and pluginRepository in pom.xml (and parent pumps too).
  • Look for the suspicious tags repository , pluginRepository and mirror in settings.xml .
  • Checking the project on another computer - copy it and try to create / run exec: java on another machine.
  • Download Maven 3.x and try running exec with it.
0
source

All Articles