我有一个这样的多模块maven项目:
my-parent
--my-domain
--my-service
--my-app <<<这是一个Spring Boot模块
我想mvn spring-boot:run直接从父模块运行命令,而不必先进入'my-app'目录.
我认为这与配置相关,spring-boot-maven-plugin但我似乎无法做到正确.
我尝试过以下方法:
使用spring-boot-starter-parent和以其他方式默认配置spring-boot-maven-plugin包含在我的应用程序的插件部分.从父级
运行会mvn spring-boot:run导致:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli) on project my-parent: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1] in the parent module
不要使用spring-boot-starter-parent.按照所述的方式
定义spring-boot-dependenciesdepManagement.在my-parent的 pluginManagement部分中
定义spring-boot-maven-plugin,并在my-app模块的plugins部分中包含插件.
运行mvn spring-boot:从父运行导致与#1相同的错误:
无法执行目标org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:在项目上运行(default-cli) my-parent:无法找到合适的主类,请添加'mainClass'属性 - > [帮助1]
不要使用spring-boot-starter-parent.按照所述的方式
定义spring-boot-dependenciesdepManagement.在my-app的插件部分中
定义.
运行mvn spring-boot:从父运行结果:spring-boot-maven-plugin
No plugin found for prefix 'spring-boot' in the current project and in the plugin groups
在上述所有情况下,mvn spring-boot:run从my-app目录运行都可以正常工作.
我认为应该有办法使这项工作.在传统的非Boot Spring项目中,配置tomcat7插件非常简单,以便我可以mvn tomcat7:run-war从父级运行,webapp子模块将按预期启动
Sla*_*vus 20
您可以通过在父pom中添加以下内容来实现:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
在你的我的应用程序(Spring Boot模块)中:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
现在您可以在项目根目录中执行:
mvn -pl my-app -am spring-boot:run
Run Code Online (Sandbox Code Playgroud)
其他参考:
| 归档时间: |
|
| 查看次数: |
4520 次 |
| 最近记录: |