Is it possible to make a Spring MVC web app run as a "standalone executable" with Java and Tomcat embedded?

huangapple go评论75阅读模式
英文:

Is it possible to make a Spring MVC web app run as a "standalone executable" with Java and Tomcat embedded?

问题

我有一个使用Java、Spring MVC和JDBC构建的Web应用程序。结果是一个WAR文件。

要运行它,用户必须安装Java 8 JDK和Tomcat,并将WAR文件部署到Tomcat服务器。

如果他们可以只下载一个文件并将其作为独立应用程序运行,那将会很棒。

也就是说,运行"WAR文件",然后只需浏览http://localhost:8080/myapp

另外,在Windows上,如果能像使用安装程序安装Tomcat时那样设置为服务器模式,那将会很不错。

有没有办法实现这个?也许可以使用Spring Boot或类似的新方法?

英文:

I have a web app built with Java, Spring MVC, and JDBC. The result is a WAR file.

To run it, the user has to install Java 8 JDK and Tomcat, and deploy the WAR file to the Tomcat server.

It would be great if they could just download the one file run it as a standalone application.

That is, run "the WAR file" and just browse to http://localhost:8080/myapp

Also, on Windows it would be great it was setup as a Server (like Tomcat is when installed with the installer).

Is there any way to do this? Maybe with Spring Boot or something new like that?

答案1

得分: 2

是的,Spring Boot 是前进的方向。
它允许您构建一个带有所有依赖项和一个嵌入的 Tomcat(默认情况下可以更改)的可执行 Jar 文件。
但用户仍然需要下载 JRE 来执行该 Jar 文件,如果需要数据库,还需要下载一个数据库,但是您可以使用内嵌数据库,比如 H2、HSQLDB 等,具体取决于您的需求。

英文:

Yep, Spring boot is the way to go.
It allows you to build an executable Jar with all dependencies and a Tomcat (by default, can be changed) embedded.
But users will still need to download a JRE to execute the Jar, and a database if it's required, but you can use en embedded database like H2, HSQLDB..., depends what is your needs.

答案2

得分: 1

可以使用Spring Boot来实现您的结果。请参考下面的链接获取示例代码:
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

英文:

Yes . you can use spring boot to achieve your results. Kindly refer the below link for sample code
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

答案3

得分: 1

你可以使用Maven来嵌入Jetty服务器,但这需要你对你的应用进行一些设置,并且可能需要调整你现有的应用。请查看这篇文章获取更多信息。

Jetty与Tomcat服务器类似,用于运行Spring应用,在开发方面没有太大的区别。Tomcat只是更加著名。

另一个选项,正如其他人所说,是将你的应用迁移到Spring Boot,如果你已经有使用Spring编写的应用,这将会很容易(但这取决于你有多少代码以及你有多少时间)。

英文:

You can use embedded jetty server using maven but that would require you to setup few things your app and may have align your existing app, please check this article for more information.

Jetty is similar to tomcat server in terms of running spring application, there are not much difference in terms of development. Tomcat is just more famous.

Other option as others said, is to migrate your app to spring boot which would be easy if you already have app written in spring (But that depends how much code you have and how much time you have)

huangapple
  • 本文由 发表于 2020年9月11日 23:18:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63849899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定