Suppose I have Maven Eclipse project. It has some classes with main, which I can run from Eclipse.
Now how can I run the same class from the command line?
The command
java -cp target/classes mypackage.MyClass
does not work, because it can't find jar files, download by maven.
The command
mvn exec:java -Dexec.mainClass="mypackage.MyClass"
also does not work due to uncomprehesive Maven errors.
How to accomplish?
UPDATE
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
UPDATE 2
If I run with the following BAT file
set MAVEN_OPTS=-Xmx16g
mvn exec:java -Dexec.mainClass="tests.Runner01"
it says
>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.
and no output occurs.