Maven 插件开发 - 如何使 Maven 阻塞直到执行完成
我有一些启动 Web 服务器并侦听请求的 java 代码。我想从自定义 Maven 插件目标启动 Web 服务器。
这工作正常(启动我的 Web 服务器并侦听请求):
public static void main(String[] args) {
MyWebServer webserver = new MyWebServer();
webserver.startServer();
}
我想将其放入自定义 Maven 插件中:
/**
*
* @goal start
*
*/
public class MyMojo
extends AbstractMojo
{
public void execute()
throws MojoExecutionException
{
(new MyWebServer()).startServer();
}
}
它几乎可以工作,只是 Maven 不会停止让 Web 服务器响应请求。它调用 startServer,然后似乎停止它并立即继续执行其他任务。
有人知道如何告诉 maven 等待/阻塞直到从命令行收到 CTRL-C 吗?我希望它的行为类似于 jetty maven 插件的工作方式。
谢谢, 戴夫
I've have some java code that starts a web server and listens for requests. I'd like to start the web server from a custom maven plugin goal.
This works fine (starts my web server and listens for requests):
public static void main(String[] args) {
MyWebServer webserver = new MyWebServer();
webserver.startServer();
}
I'd like to put this inside a custom maven plugin:
/**
*
* @goal start
*
*/
public class MyMojo
extends AbstractMojo
{
public void execute()
throws MojoExecutionException
{
(new MyWebServer()).startServer();
}
}
It almost works, except that Maven doesn't stop to let the web server respond to requests. It calls startServer and then appears to stops it and immediately continues on with other tasks.
Anyone know how to tell maven to wait/block until it receives CTRL-C from command line? I'd like it to behave similar to the way the jetty maven plugin works.
Thanks,
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点黑客,但简单地添加一个
System.in.read()
就可以了:我还发现这个问题对于其他使用 Maven 插件的人来说可能有用:Maven 插件执行另一个插件
A bit of a hack, but simply adding a
System.in.read()
does the trick:I also found this question which might be useful for others working on maven plugins: Maven plugin executing another plugin