我如何将spring mvc应用程序打包到jar? [英] how can i package spring mvc application to jar?

查看:1117
本文介绍了我如何将spring mvc应用程序打包到jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 maven spring mvc tomcat7-maven-构建的应用程序插件。我可以将这些打包到jar文件中,以便我可以运行jar文件来启动tomcat服务器吗?



这意味着我不需要tomcat,只有jar文件可以提供Web服务。

解决方案

Spring文档是你的朋友。我提供了您可以关注的链接,以及本文中突出显示的部分。



Spring Boot Maven Packaging



一次spring-boot-maven-plugin已经包含在你的 pom.xml 中,它会自动尝试使用 spring-boot重写存档以使它们可执行:重新包装目标。您应该使用 pom.xml中的常用包装元素来配置项目以构建jar或war(视情况而定)



您要启动的主类可以使用配置选项指定,也可以通过以常规方式向清单添加 Main-Class 属性。 / p>

要构建和运行项目工件,您可以输入以下内容:

  $ mvn package 
$ java -jar target / mymodule-0.0.1-SNAPSHOT.jar

有关该插件的更多信息,请访问此处


I have an application built using maven and spring mvc and tomcat7-maven-plugin. Can I package these to a jar file, so that i can run the jar file to start a tomcat server?

That means i don't need tomcat, only a jar file can provide a web service.

解决方案

Spring documentation is your friend. I am providing the links which you can follow, with highlighted parts in this post.

Spring Boot Maven Packaging

Once spring-boot-maven-plugin has been included in your pom.xml it will automatically attempt to rewrite archives to make them executable using the spring-boot:repackage goal. You should configure your project to build a jar or war (as appropriate) using the usual packaging element in the pom.xml

The main class that you want to launch can either be specified using a configuration option, or by adding a Main-Class attribute to the manifest in the usual way.

To build and run a project artifact, you can type the following:

$ mvn package 
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

More information about the plugin is available here

这篇关于我如何将spring mvc应用程序打包到jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆