如何在Visual Studio Code上添加Tomcat服务器?

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

How to add tomcat server on visual studio code?

问题

我的当前Spring Boot项目运行没有错误,但无法显示在网页上。我认为这是因为我需要一个Tomcat服务器。
因此我从名为Tomcat for Java的扩展中安装了它。

但是在我安装完之后,我找不到它的位置路径。因此我无法添加Tomcat服务器,也无法在网页上运行。在Windows计算机上,这可以很容易地完成。

我正在使用Mac。请指导我如何操作。

如何在Visual Studio Code上添加Tomcat服务器?

英文:

My current spring boot project is running without error, but it cannot show on the Web page. I think because I need a Tomcat server.
So I installed it from extension called Tomcat for Java

But after I installed it, I can't find its location path. So I cant add a tomcat server and cant run on the web page. In the window computer, it is can select easily.

I am using mac . Please guide me with it

如何在Visual Studio Code上添加Tomcat服务器?

答案1

得分: 2

首先,你不需要另外安装Tomcat来运行你的Spring Boot应用,因为Spring Boot默认已经为你嵌入了Tomcat(前提是你在pom.xml文件中有spring-boot-starter-web依赖)。

当你编码完成后,前往项目目录,执行以下命令:

mvn clean install

这将会把你的应用打包成一个jar/war文件(基于pom.xml配置)。在你的target文件夹中,会生成一个jar/war文件。你可以直接在target文件夹中打开终端,并运行以下命令:

java -jar your_JarName.jar

这将会启动你的Spring Boot应用。然后在浏览器中输入http://localhost:8080/hello?name=abc,你应该能够看到输出结果。

如果没有生效,检查一下你是否修改了application.properties文件中的默认端口。如果你的application.properties中有server.port=8081,那么你需要相应地修改URL为http://localhost:8081/hello?name=abc

英文:

First of all, you don't need another tomcat to run your spring boot application as spring boot has a tomcat embedded for you by default (Provided you have spring-boot-starter-web dependency in your pom.xml file).

Once you have coded everything, go to your project directory and do a

mvn clean install

This will package your application into a jar/war file (based on pom.xml). In your target folder you will have a jar/war file generated. You can simply open terminal in your target folder and run

java -jar your_JarName.jar

This will start your spring boot app. Now go to the browser and load http://localhost:8080/hello?name=abc you should be able to see the output.

If it doesn't work, check if you have changed the default port in your application.properties file. If your application.properties has server.port=8081 then you need to modify your URL accordingly http://localhost:8081/hello?name=abc

huangapple
  • 本文由 发表于 2020年4月10日 13:56:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/61134790.html
匿名

发表评论

匿名网友

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

确定