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

时间:2014-11-09 19:21:36

标签: java eclipse maven command-line

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

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

命令

java -cp target/classes mypackage.MyClass

不起作用,因为它无法找到jar文件,可以通过maven下载。

命令

mvn exec:java -Dexec.mainClass="mypackage.MyClass"
由于不兼容的Maven错误,

也无效。

如何完成?

更新

mvn printout:

>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.

并且没有输出。

0 个答案:

没有答案