有谁知道是否可以在mvn聚合POM上运行mvn exec:java?
目前我得到:
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 $
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">
<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</url>
<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>
我要执行的类(codadris.coviob2.App_Coviob2)位于模块codadris.dbgui
任何想法?
TIA
抱歉,可能格式不正确。我对换行有一些问题。
答案 0 :(得分:5)
根据Exec Maven Plugin Documentation关于exec:java
:
在当前VM中执行提供的java类,并将封闭项目的依赖项作为类路径。
在这里,您显示的聚合pom不包含对codadris.dbgui
模块的任何依赖(这实际上是好事,不要添加它!),因此java.lang.ClassNotFoundException
。
要避免这个java.lang.ClassNotFoundException
,第一个选项是从包含Java类的模块运行exec:java
目标,如另一个答案中所指出的。但这不是你所要求的。
幸运的是,还有另一种选择 - 使用插件依赖关系 - 在Using Plugin Dependencies Instead of Project Dependencies中有记录:
有时候,在不影响项目依赖性的情况下执行Java类是可取的。例如,如果您使用的是Maven csharp插件,那么将Java依赖项添加到项目中将会破坏csharp编译器。因此, Exec Maven插件允许您将可执行类的依赖项指定为插件依赖项。由于Maven在确定多模块项目的构建顺序时会考虑插件依赖性,因此构建顺序应自动进行适当调整(我认为)。
[...]
这应该是诀窍。有关exec-maven-plugin配置和使用插件依赖性的示例POM配置的更多详细信息,请参阅上面给出的链接。
PS:我在这里有点困惑,因为 exec:java
抱怨无法找到pom.xml(“Cannot execute mojo: java. It requires a project with an existing pom.xml, but the build is not using one.
”)。也许只是跟踪不准确,但这让我怀疑父母的位置。
PPS:PS不再适用,OP已用正确的跟踪更新了问题。
答案 1 :(得分:1)
我建议您cd
向下到相关课程所在的模块并在那里运行exec:java
。 exec:java
documentation表示它“在当前VM中执行提供的java类,并将封闭项目的依赖项作为类路径。”,所以即使您没有上面列出的错误,它仍然会失败,因为它会超出父POM的依赖(没有任何),而不是孩子的。错误堆栈跟踪有点奇怪,但是当插件以不适合使用的方式使用时,这通常很常见(不幸的是)。