代码之家  ›  专栏  ›  技术社区  ›  Sven Efftinge

从Maven中的测试范围运行main:“缺少目标org.codehaus.mojo:exec Maven plugin:1.6.0:java的参数‘mainClass’或参数无效”

  •  1
  • Sven Efftinge  · 技术社区  · 7 年前

    我想执行一个位于testsrc文件夹中的主类。 我试过:

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

    [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]
    

    Open in Gitpod

    编辑: 这样写很有效:

    mvn -q exec:exec \
        -Dexec.executable=java \
        -Dexec.args="-cp %classpath com.example.beanoverriding.EmbeddedApplication" \
        -Dexec.classpathScope="test"
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Martijn    7 年前

    根据文档,您确实应该设置exec.mainClass属性。但在主流阶级看来,这确实是不可能的。

    在使用 -X 选择权( mvn -X exec:java -Dexec.mainClass=com.example.beanoverriding.EmbeddedApplication -Dexec.classpathScope=test

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

    start-class 所有物因此,该属性似乎在某些配置中被覆盖。事实上,的确如此。在房间里 spring-boot-starter-parent 波姆。看见 https://github.com/spring-projects/spring-boot/blob/v2.1.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml

    因此,在当前配置中,以下命令将执行此任务:

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

        2
  •  0
  •   Jeff MAURY    7 年前

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