4

I want to execute a main class that sits in the test src folder. I tried:

mvn -q exec:java \
    -Dexec.mainClass=com.example.beanoverriding.EmbeddedApplication \
    -Dexec.classpathScope="test"

But get:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project bean-overriding: 
        The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid -> [Help 1]

See the code in action:

Open in Gitpod

Edit: Writing it like this works:

mvn -q exec:exec \
    -Dexec.executable=java \
    -Dexec.args="-cp %classpath com.example.beanoverriding.EmbeddedApplication" \
    -Dexec.classpathScope="test"
Sven Efftinge
  • 3,065
  • 17
  • 17
  • Perhaps the main class value should be between double quotes? See for example https://stackoverflow.com/a/9846103/412834 . – reinouts Nov 29 '18 at 12:25
  • There's indeed no `mainClass` parameter in the [exec](https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html) goal. `mainClass` is only available in the [java](https://www.mojohaus.org/exec-maven-plugin/java-mojo.html) goal. So `executable` + `args` seem to be the correct solution. – lexicore Nov 29 '18 at 15:45

2 Answers2

3

According to the documentation you should indeed set the exec.mainClass property. But that indeed does not seem to the the main class.

When executing the command with the -X option (mvn -X exec:java -Dexec.mainClass=com.example.beanoverriding.EmbeddedApplication -Dexec.classpathScope=test) Maven shows some more info with regards to the configuration:

    <configuration>
      ...
      <classpathScope default-value="runtime">${exec.classpathScope}</classpathScope>
      ...
      <mainClass>${start-class}</mainClass>
      ...
    </configuration>

It seems the main class is set by the start-class property... So it seems that the property is overridden in some configuration. And indeed, it is. It's in the spring-boot-starter-parent pom. See https://github.com/spring-projects/spring-boot/blob/v2.1.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml

So with your current configuration, the following command will do the job:

mvn -X exec:java -Dstart-class=com.example.beanoverriding.EmbeddedApplication -Dexec.classpathScope=test

Martijn
  • 111
  • 2
0

Use classpathScope=test (seehttps://www.mojohaus.org/exec-maven-plugin/java-mojo.html#classpathScope)

Jeff MAURY
  • 166
  • 3