views:

840

answers:

2

Hi. Does anyone know whether it is possible to run mvn exec:java on mvn aggregate POM?

Currently I get:

2009-09-24 02:24:14.404  :bash: karolrvn@karolrvn-laptop : ~/adfadf/programming/verknowsys/codadris/ide_projects $ mvn exec:java -e -Dexec.mainClass=codadris.coviob2.App_Coviob2
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   net.jcip.annotations
[INFO]   codadris.utils
[INFO]   codadris.binblocklang
[INFO]   jargs
[INFO]   codadris.dbapp
[INFO]   codadris.dbgui.scala
[INFO]   flexdock_codadris
[INFO]   codadris.gui.utils
[INFO]   codadris.gui
[INFO]   codadris.gui.treetable
[INFO]   codadris.gui.textedit
[INFO]   codadris.gui.screenspace
[INFO]   codadris.gui.suite
[INFO]   codadris.dbgui
[INFO]   All Codadris modules aggregate POM
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building net.jcip.annotations
[INFO]    task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. codadris.coviob2.App_Coviob2

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. codadris.coviob2.App_Coviob2
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
  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:287)
  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)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. codadris.coviob2.App_Coviob2
  at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
  at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
  ... 16 more
Caused by: java.lang.ClassNotFoundException: codadris.coviob2.App_Coviob2
  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
  at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283)
  at java.lang.Thread.run(Thread.java:619)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Sep 24 02:24:17 CEST 2009
[INFO] Final Memory: 4M/94M
[INFO] ------------------------------------------------------------------------
2009-09-24 02:24:17.917  :bash: karolrvn@karolrvn-laptop : ~/adfadf/programming/verknowsys/codadris/ide_projects $

The POM:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd"&gt;
 <modelVersion>4.0.0</modelVersion>
 <groupId>codadris</groupId>
 <artifactId>codadris</artifactId>
 <packaging>pom</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>All Codadris modules aggregate POM</name>
 <url>http://maven.apache.org&lt;/url&gt;
 <modules>
  <module>codadris.binblocklang</module>
  <module>codadris.dbapp</module>
  <module>codadris.dbgui</module>
  <!-- <module>codadris.dbgui.scala</module> -->
  <module>codadris.gui</module>
  <!--<module>codadris.gui.scala</module>-->
  <module>codadris.gui.screenspace</module>
  <module>codadris.gui.suite</module>
  <module>codadris.gui.textedit</module>
  <module>codadris.gui.treetable</module>
  <module>codadris.gui.utils</module>
  <module>codadris.utils</module>
<!--  <module>ekit_codadris</module>-->
  <module>flexdock_codadris</module>
  <module>jargs</module>
  <module>net.jcip.annotations</module>
  <module>codadris.dbgui.scala</module>
 </modules>

 <!-- 2009-08-27 06:04:10 ; karolrvn ; http://stackoverflow.com/questions/1274523/maven-surefire-reporting-plugin-configuration -->
 <reporting>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-report-plugin</artifactId>
<!--     <version>2.4.2</version> -->
    <configuration>
     <aggregate>true</aggregate>
     <!--also set this to link to generated source reports-->
     <linkXRef>true</linkXRef>
    </configuration>
   </plugin>
  </plugins>
 </reporting>


</project>

the class, which i want to execute ( codadris.coviob2.App_Coviob2 ) is in module codadris.dbgui

Any ideas?
TIA
Sorry for probably not exactly too correct formatting. I had some problem with newlines.

A: 

I recommend you cd down to the module where the class in question resides and run exec:java there. The exec:java documentation says it "Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath.", so even if you didn't have the error you listed above, it still would fail because it would be exceuting with the parent POM's dependencies (there aren't any) rather than the child's. The error stack trace is a little odd, but that's often typical (unfortunately) when a plug-in is used in a way it is not designed to work in.

SingleShot
+3  A: 

According to the Exec Maven Plugin Documentation about exec:java:

Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath.

Here, the aggregating pom you are showing doesn't contain any dependency to the codadris.dbgui module (which is actually good thing, don't add it!), hence the java.lang.ClassNotFoundException.

To avoid this java.lang.ClassNotFoundException, a first option would be to run exec:java goal from the module containing the Java class as pointed out in another answer. But this is not what you're asking for.

Luckily, there is another option - using Plugin Dependencies - which is documented in Using Plugin Dependencies Instead of Project Dependencies:

Ocassionally it is desirable to execute a Java class without affecting your project's dependencies. For example, if you are using the Maven csharp plugins, adding Java dependencies to your project will upset the csharp compiler. Therefore the Exec Maven Plugin allows you specify dependencies of your executable class as plugin dependencies. Since Maven takes plugin dependencies into consideration when determining build order for a multi-module project your build order should automatically be appropriately adjusted (I think).

[...]

This should to the trick. Refer to the link given above for more details about the exec-maven-plugin configuration and an Example POM Configuration using Plugin Dependencies.

PS: I'm a bit confused here because exec:java is complaining about not being able to find a pom.xml ("Cannot execute mojo: java. It requires a project with an existing pom.xml, but the build is not using one."). Maybe it's just the trace that isn't accurate but this makes me doubting about the parent pom location.

PPS: The PS doesn't apply anymore, the OP has updated the question with the right trace.

Pascal Thivent
I'm sorry, i pasted wrong console dump, which was a result of execution in wrong dir. The real error is java.lang.ClassNotFoundException: codadris.coviob2.App_Coviob2
karolrvn
Ok, this seems more accurate and logical.
Pascal Thivent
+1 I think this will resolve the issue
Rich Seller