I type the following in a Windows shell in the root of a Maven project that contains a class with a
public static void main(String[] args)
method that I'd like to run.
mvn exec:java -Dexec.mainClass="com.spp.config.main.SqlGeneratorHarness" -e
The class exists and is compiled in that package
(i.e., target/classes/com/spp/config/main/SqlGeneratorHarness.class).
I see...
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task '.mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify a valid
lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] Trace org.apache.maven.BuildFailureException: Invalid task' .mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify
a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1830)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Sep 27 14:33:52 PDT 2011
[INFO] Final Memory: 3M/122M
[INFO] ------------------------------------------------------------------------
I've tried variations like
mvn exec:exec -Dexec.executable="java" [...]
and
mvn org.codehaus.mojo:exec-maven-plugin:1.2.1:java [...]
to no avail. What gives?
I'm running Maven 2.2.1, Java JDK 1.6.0_27 on Windows 7 Enterprise 64-bit.
A snippet from my pom.xml for the exec-maven-plugin is...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
</plugin>
where the version is set in the <properties>
So... revisiting this... if you use Windows PowerShell, you will get the exception I originally reported. If, however, you use cmd.exe, then you should be able to run the class with the command as I posted (with or without wrapping double-quotes).
There's something very basic going wrong. Try losing the quotation marks. They're not needed there. In fact, try starting with something simpler, like
mvn -e exec:java -Dexec.mainClass=foo
That should give you the error "An exception occured while executing the Java class. foo", and the root cause should be a ClassNotFoundException:
Caused by: java.lang.ClassNotFoundException: foo
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
Type it out yourself. Don't copy/paste the command from somewhere else.
Just a quick checklist:
Rename ~/.m2 folder and run mvn exec:java ... again and let Maven to download everything again from central.
Check that your exec plugin is downloaded from central. (Check that your local repository contains the same files as the central.)
Looking for suspicious repository and pluginRepository tags in the pom.xml (and parent poms as well).
Looking for suspicious repository, pluginRepository and mirror tags in the settings.xml.
Checking the project in an other machine - copy it and try to build/run exec:java in an other machine.
Download Maven 3.x and try to run the exec with it.
Related
I tried running first of the WordCount examples and it works in Eclipse (I have Windows 7 OS), but not in shell, using the command:
mvn compile exec:java -Dexec.mainClass=com.google.cloud.dataflow.examples.MinimalWordCount
I have installed Maven and configured JAVA_HOME and Path variables and so on, however, I'm not sure what I must have missed. This is the output:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Tutorial ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Java\eclipse-jee-luna-SR2-win32-x8
6_64\eclipse\workspace\Tutorial\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) # Tutorial --
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) # Tutorial ---
[WARNING]
java.lang.ClassNotFoundException: com.google.cloud.dataflow.examples.MinimalWord
Count
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:744)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.011 s
[INFO] Finished at: 2015-11-03T01:11:57+01:00
[INFO] Final Memory: 17M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java
(default-cli) on project Tutorial: An exception occured while executing the Java
class. com.google.cloud.dataflow.examples.MinimalWordCount -> [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/MojoExecutionE
xception-
I am in the dark about how to proceed and would very much appreciate ideas of where to look next and other things to try.
Thanks!
You may have run into an issue with the documentation.
The command line you are using should work if you have cloned GoogleCloudPlatform/DataflowJavaSDK-examples. The mention of the particular repo to clone is way back in "getting started", not at all obvious if you head straight to WordCount Example Pipeline.
But if you generated the project from the Cloud Dataflow Plugin for Eclipse (or via a Maven archetype) then the examples are placed into your Java package. So instead of com.google.cloud.dataflow.examples.MinimalWordCount you will use the name my.java.project.MinimalWordCount, where my.java.project is whatever package name you chose when you created the project.
Or if you have cloned the SDK itself from GoogleCloudPlatform/DataflowJavaSDK then you will need to add -pl examples to your command line. This is because the SDK's repository is factored into maven modules; this flag instructs maven to run in the context of the examples module.
If you have a multi-module maven project (DataflowJavaSDK, not DataflowJavaSDK-examples), you can do mvn compile in the top directory, then cd into examples and then issue the mvn exec:java -Dexec.mainClass=... command there.
Im trying to build a legacy project, which has dependencies like torque. When I try to execute the command mvn torque:create-db
But I see the following error
D:\someproject\cps-rfq\someproject-new\someproject>mvn torque:create-db
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin descriptor for the plugin Plugin [torque:maven-torque-plugin]
was not found. Please verify that the plugin JAR D:\someproject\cps-rfq\lib\torque\ma
ven-torque-plugin\3.3-RC3\maven-torque-plugin-3.3-RC3.jar is intact.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.IllegalStateException: The plugin descriptor for the plugin Plugin [to
rque:maven-torque-plugin] was not found. Please verify that the plugin JAR D:\IR
DEV\cps-rfq\lib\torque\maven-torque-plugin\3.3-RC3\maven-torque-plugin-3.3-RC3.
jar is intact.
at org.apache.maven.plugin.DefaultPluginManager.addPlugin(DefaultPluginM
anager.java:360)
at org.apache.maven.plugin.DefaultPluginManager.verifyVersionedPlugin(De
faultPluginManager.java:224)
at org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPlug
inManager.java:184)
at org.apache.maven.plugin.DefaultPluginManager.loadPluginDescriptor(Def
aultPluginManager.java:1642)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(Defa
ultLifecycleExecutor.java:1540)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor
(DefaultLifecycleExecutor.java:1787)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListBy
AggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.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)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sat Jun 29 11:56:10 IST 2013
[INFO] Final Memory: 1M/15M
[INFO] ------------------------------------------------------------------------
But I can see the D:\someproject\cps-rfq\lib\torque\maven-torque-plugin\3.3-RC3\maven-torque-plugin-3.3-RC3.jar file in the repo.
I would suggest to use the final release version like this:
mvn torque:maven-torque-plugin:3.3:create-db
Furthermore i would suggest to first try to delete the folder in your local repository:
D:\someproject\cps-rfq\lib\torque
And retry your build, cause it looks weired that the RC version has been in use instead of the release version.
Trying to follow step #4 in this Hibernate tutorial:
mvn exec:java -Dexec.mainClass="org.hsqldb.Server" -Dexec.args="-database.0 file:target/data/tutorial"
I am getting this error:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building First Hibernate Tutorial
[INFO] task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
[WARNING]
java.lang.ClassNotFoundException: org.hsqldb.Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:662)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. org.hsqldb.Server
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Dec 17 16:35:42 EST 2012
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
This is despite downloading the latest hsqldb package and installing it per the FAQ. The hsqldb.jar file is located in C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib and the classpath env var points at it:
CLASSPATH=C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib
So why am I receiving this ClassNotFoundException: org.hsqldb.Server error?
What am I doing wrong?
First of all, your CLASSPATH is not generally correct for any jar. A jar name must be specified, for example:
CLASSPATH=C:\hsqldb-2.2.9\hsqldb-2.2.9\hsqldb\lib\hsqldb.jar
Second, CLASSPATH is not necessary for this tutorial, as it is a Maven project. You should add the relevant dependency to the pom.xml file that is described in section 1.1.1 of the tutorial you mention. Simply add this block to the ones listed in the pom.xml, inside the tab:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
According to http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html, you need to specify the whole path ending with .jar. If there are multiple jar files, maybe try specifying C:\path\to\hibernate*.jar
If you only specify directories, only *.class files are loaded.
Other possiblity is the CLASSPATH variable you set only valid for a shell session, not globally -- hence the maven command is not reading it. Try setting it via Windows system settings.
I would recommend to download fresh copy of tutorial from http://sourceforge.net/projects/hibernate/files/hibernate3/3.3.2.GA/ and try to build it. If you will be missing dependendiens like hsqldb or commons-logging and others I got this problem solved by adding maven project repository - https://repository.jboss.org/nexus/content/repositories/thirdparty-releases. Once all artifacts downloaded I was able to run HSQLDB server. Would recommend to compare your current project with freshly downloaded one. It should solve your problem.
Our Maven build is suddenly failing in Jenkins as of August 2nd. We cannot explain why maven failsafe cannot access it's dependent "booter" plugin.
Has anyone seen the same thing?
[INFO] [failsafe:integration-test {execution: run-integration-tests}]
[INFO] Failsafe report directory: /var/lib/jenkins/workspace/Foo/integration-tests/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unable to locate surefire-booter in the list of plugin artifacts
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.RuntimeException: Unable to locate surefire-booter in the list of plugin artifacts
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.getForkConfiguration(AbstractSurefireMojo.java:1152)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:655)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAllProviders(AbstractSurefireMojo.java:647)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:606)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:569)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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)
The problem is confined to Maven Failsafe 2.12.1 which a directory listing from the Apache repo shows was released late on August 1st.
The workaround is to fix your version in your POM to the earier 2.12 or you might also want to try later versions such as 2.12.2 or 2.12.3 (which post date this answer). I have not tried these later versions and "2.12" is the version string that worked for me.
Just add chosen version where the plugin is declared in the POM.
Presumably this works because only 2.12.1 has the problem (which is undiagnosed, AFAICT)
I ran into this problem using Maven 2. Switching to Maven 3 resolved my issue. Also Simon's answer of incrementing the maven-surefire-plugin worked with Maven 2.
I have inherited a codebase :)
Under src/test/java/ there's a file that I need to run (I need to run its public static void main(String[] args), not a #Test method within it).
The closest I have got is:
mvn -e exec:java -Dexec.mainClass="com.me.packagex.RunFile" -Dexec.classpathScope="test"
but that then fails, and it appears to be because RunFile wants to use classes that exist under src/main/java/com/me/packagex/ (notice, /main/, not /test/). The files under there are in the same package as RunFile, i.e. 'package com.me.packagex;'.
If I remove the -Dexec.classpathScope="test" then it can't find RunFile at all. It's as if I need to give it two scopes, but it doesn't accept "test,compile".
The person I've inherited this from (dearly departed) used to run it from Eclipse. I need a way to run it from the command-line.
I hope this is clearly explained.
tyvm,
This is promising. Pascal, I've tried your example and that doesn't work for me.
Although now I look at it - it's not finding Demo, rather than not finding Dog.
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_18
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-25-generic" arch: "i386" Family: "unix"
$ mvn -e exec:java -Dexec.mainClass="com.stackoverflow.Demo" -Dexec.classpathScope="test"
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. com.stackoverflow.Demo
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. com.stackoverflow.Demo
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
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. com.stackoverflow.Demo
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:346)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: java.lang.ClassNotFoundException: com.stackoverflow.Demo
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:284)
at java.lang.Thread.run(Thread.java:619)
I faced the same problem and figured it out.
Shortly speaking, the class must be compiled before exec:java goal. (It surely works without test-compile phase if the class is already compiled by other user action. Note that Pascal Thivent, in his answer, invoked mvn test before exec:java.)
$ mvn -Dexec.mainClass=... -Dexec.classpathScope=test test-compile exec:java
You can prove it for yourself if you want to see the ClassNotFoundException again.
$ mvn -Dexec.mainClass=... -Dexec.classpathScope=test clean exec:java
Include following lines in pom.xml in exec-maven-plugin plugin. <classpathScope>test</classpathScope>
plugin section in POM looks something like this
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-execution</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.MainClass</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
Note : com.example.MainClass is the class containing main method.
(...) I hope this is clearly explained.
Not bad but I can't reproduce. I created a project:
$ mvn archetype:generate -DgroupId=com.stackoverflow \
-DartifactId=Q4060613 \
-Dversion=1.0-SNAPSHOT \
-DarchetypeArtifactId=maven-archetype-quickstart
Then cded into it and created a Dog class (under src/main/java):
$ cd Q4060613
$ cat > src/main/java/com/stackoverflow/Dog.java
package com.stackoverflow;
public class Dog {
public String bark() {
return "woof!";
}
}
and created a Demo class (under src/test/java):
$ cat > src/test/java/com/stackoverflow/Demo.java
package com.stackoverflow;
public class Demo {
public static void main(String[] args) {
System.out.println(new Dog().bark());
}
}
After compiling the source code, running the command you provided works as expected:
$ mvn test
...
$ mvn exec:java -Dexec.mainClass="com.stackoverflow.Demo" -Dexec.classpathScope="test"
[INFO] Scanning for projects...
...
[INFO] --- exec-maven-plugin:1.2:java (default-cli) # Q4060613 ---
woof!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
Something else must be wrong.
Ok, spurred on by it working for everyone else I dug a little harder. The code wasn't reporting its problems very well and I was misreading the stacktrace.
It does:
FileInputStream is = new FileInputStream("lib/other-thing.jar");
which was failing. I symlinked trunk/src/main/assembly/lib/ into trunk/ and now it works. There might be a neater way to fix that then the symlink, though.
Thank you chaps.