从 Jar 运行 Maven Jetty
这是我想做的。我创建了一个 Maven 项目并在 Eclipse 中为其配置了 jetty 插件...
因此,如果我在 Eclipse 中运行并将 Maven 目标设置为 jetty:run
,它将在 jetty 中运行我的项目web.xml 中指定的端口。现在我想构建 jar 文件,当我执行 java -jar myapp.jar
时,它会自动调用 jetty:run
。
我该怎么做?
Here is want I want to do. I created a maven project and configured the jetty plugin for it in eclipse...
So from Eclipse if I do run and set the maven goal there to be jetty:run
it runs my project in jetty on the port specified in web.xml. Now I want to build the jar file and when I do java -jar myapp.jar
it will automatically call jetty:run
.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想打包您的应用程序,以便可以将其交给某人并让他们将其作为独立应用程序运行,而无需将 war 文件部署到 Web 容器中,那么这与执行 mvn 是不同的问题jetty:run 在开发时,我会调用部署时以避免任何混淆
在部署时,我们不能假设机器上会有 maven,因此没有
mvn jetty:run
,即使有,这也不会工作,除非我们提供源代码来在开发环境中运行构建!可以通过将应用程序战争中的 jetty jar 与 Main 类捆绑在一起来打包独立的 Web 应用程序,以编程方式启动 jetty,并让它运行应用程序战争。这依赖于这样一个事实:WAR 和 JAR 的文件和目录结构不同,因此两者之间没有明显的重叠,这就是使此解决方法成为可能的原因,并且还留下了将 war 文件部署在可能的 Web 容器
有一个 maven 插件 嵌入 winstone 这是另一个轻量级 servlet 容器
对于jetty,您可以先阅读使用 Maven 嵌入 Jetty 7 webapp 可执行文件
If you want to package your application so that you can hand it to someone and have them run it as a standalone application without having to go through deploying a war file into a web container, then that is a different concern from doing
mvn jetty:run
at development time, I will call that deployment time to avoid any confusionAt deployment time, we can't assume there will be maven on the machine, thus no
mvn jetty:run
, and even if there was, this would not work, unless we deliver the source code to run the build as in the development environment!A standalone web application can be packaged by bundling the jetty jars in the application war along with a Main class to start jetty programmatically, and get it to run the application war. This relies on the fact that the file and directory structure of the WAR and JAR are different, and thus there is no significant overlap between the two, which is what makes this workaround possible, and it also leaves the option of deploying the war file in a web container possible
There is a maven plugin that embeds winstone which is another lightweight servlet container
For jetty, you may start by reading Embedded Jetty 7 webapp executable with Maven