Java 如何从命令行从maven Eclipse项目运行类?

Java 如何从命令行从maven Eclipse项目运行类?,java,eclipse,maven,command-line,Java,Eclipse,Maven,Command Line,假设我有Maven Eclipse项目。它有一些带有main的类,我可以从Eclipse运行这些类 现在如何从命令行运行同一个类 命令 java -cp target/classes mypackage.MyClass mvn exec:java -Dexec.mainClass="mypackage.MyClass" 不起作用,因为它找不到jar文件,由maven下载 命令 java -cp target/classes mypackage.MyClass mvn exec:java -

假设我有Maven Eclipse项目。它有一些带有main的类,我可以从Eclipse运行这些类

现在如何从命令行运行同一个类

命令

java -cp target/classes mypackage.MyClass
mvn exec:java -Dexec.mainClass="mypackage.MyClass"
不起作用,因为它找不到jar文件,由maven下载

命令

java -cp target/classes mypackage.MyClass
mvn exec:java -Dexec.mainClass="mypackage.MyClass"
由于不可理解的Maven错误,也无法工作

如何完成

更新

mvn打印输出:

>mvn exec:java -Dexec.mainClass="tests.Runner01"
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for tests:Try_MultidimBenchmark:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.scope' for ch.qos.logback:logback-classic:jar must be one of [provided, compile, runtime, test, system] but is '${logging.scope}'. @ line 14, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Try_MultidimBenchmark 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ Try_MultidimBenchmark ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[WARNING]
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.OutOfMemoryError: Java heap space
        at tests.Runner01.main(Runner01.java:47)
        ... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.031 s
[INFO] Finished at: 2014-11-09T23:51:31+04:00
[INFO] Final Memory: 1840M/4547M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project Try_MultidimBenchmark: An exception occured while executing the Java class. null: InvocationTarge
tException: Java heap space -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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
更新2

如果我使用以下BAT文件运行

set MAVEN_OPTS=-Xmx16g
mvn exec:java -Dexec.mainClass="tests.Runner01"
上面说

>runme.bat

>set MAVEN_OPTS=-Xmx16g

>mvn exec:java -Dexec.mainClass="tests.Runner01"
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for tests:Try_MultidimBenchmark:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.scope' for ch.qos.logback:logback-classic:jar must be one of [provided, compile, runtime, test, system] but is '${l
ogging.scope}'. @ line 14, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Try_MultidimBenchmark 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ Try_MultidimBenchmark ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

并且没有输出。

@OliverCharlesworth是正确的-请编辑您的问题以反映Maven给您的错误消息(特别是在
mvn exec:java-Dexec.mainClass=“mypackage.MyClass”
命令上),否则我们将无法帮助您。要快速修复,尝试将插件添加到您的
pom.xml
文件中-如果它有效,请进一步研究到底是什么导致了您的问题,并看看是否有更好的解决方案。不管是哪种方式,都要报告。通常最简单的解决方法是对您的项目使用
java-jar