Chapter 02: MojoExecutionException
2 posts
tushar_mahapatra
|
I am getting ClassNotFoundException->MojoExecutionException->LifecycleExecutionException exceptions when trying the 'mvn exec:java' command. Previously, I struggled for half a day getting a successful compile. I had tried 'mvn clean' and 'mvn compile' at both the 'chapter02' folder and its parent folder levels. Here is an extract of the log:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli) on project chapter02: An exception occured while executing the Java class. com.apress.javaee6.chapter02.Main -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli) on project chapter02: An exception occured while executing the Java class. com.apress.javaee6.chapter02.Main
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:203)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
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.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. com.apress.javaee6.chapter02.Main
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:346)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
... 19 more
Caused by: java.lang.ClassNotFoundException: com.apress.javaee6.chapter02.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:284)
at java.lang.Thread.run(Thread.java:662)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Any ideas or suggestions on how I should proceed now?
Thanks in advance.
|
tushar_mahapatra
|
Never mind. I could get ahead.
I had forgotten to mention before that although my compile of chapter02 succeeded, my compile of the root folder did not. I was getting errors relating to the 'lookup()' method. Thinking that might be related to my 'mvn exec' problem with chapter02, I googled, reached http://getsatisfaction.com/javaee6/topics/chapter_13_common_annotation_1_1 (also found here, I think), and followed the advice there, adding 'endorsed' folders to JAVA_HOME and JRE_HOME folders. I continued getting the same errors. After some struggling, I discovered that my PATH variable referred to the JRE inside JAVA_HOME. I copied the 'endorsed' folder inside the 'jre' tree in JAVA_HOME and the root compile errors stopped.
For chapter02, I ultimately found that I was using the wrong command. I was executing the following command from the book:
mvn exec:java -Dexec.mainClass="com.apress.javaee6.chapter02.Main"
However, I had forgotten that I had copied the latest source code from here (the Project Kenai web site). I checked the package used in the source code and found it to be different. The following corrected command worked.
mvn exec:java -Dexec.mainClass="org.beginningee6.book.chapter02.Main"
Hope these resolutions to two different problems are helpful to somebody.
|