Visual Studio Code设置用于没有主方法的Java WebApp项目。

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

Visual Studio Code setup for Java WebApp Project without main method

问题

我正在尝试在我的本地机器上设置这个项目(https://github.com/afawcett/githubsfdeploy)。我对Java不太熟悉,但我觉得我已经做了足够的事情(MAVEN、Java环境下载和系统变量设置),让我的Windows机器和Visual Studio Code一起运行起来。我能够在Visual Studio Code中顺利运行Spring Boot项目,所以我想我已经拥有了所有所需的组件(https://code.visualstudio.com/docs/java/java-spring-boot)。

这个Spring Boot项目有一个主方法,而我正在尝试重新创建的项目没有。当我调试githubsfdeploy项目时,我收到一个错误,说找不到“main”方法。我一直在研究如何在不使用主方法的情况下运行Java项目,但我还没有找到缺失的部分。希望能指导我可能没有考虑到的问题。谢谢!

英文:

I am looking to setup this project ( https://github.com/afawcett/githubsfdeploy) on my local machine. I'm not too familiar with Java but I feel I've been able to do enough (MAVEN, JAVA environment downloads and system variable settings) to get my windows machine up and running along with Visual Studio Code. I was able to get the spring boot project up and running in visual studio code without any issues so I want to believe I have all the required pieces (https://code.visualstudio.com/docs/java/java-spring-boot).

The spring-boot project has a main method and the one I'm trying to recreate doesn't. I am receiving the error when debugging the githubsfdeploy project that a "main" method could not be found. I've been researching other ways to run a java project without using the main method but haven't recognized the missing piece yet. Would love some direction on what I may not be taking into account. Thanks!

答案1

得分: 2

这是一个基于项目对象模型(POM)概念的Maven项目。因此,首先,您应该在本地下载MavenTomcat

我的电脑配置:win10,vscode1.49.0,JDK11

已安装的VS Code扩展:Java扩展包适用于Java的Tomcat

我已下载:apache-maven-3.6.3-bin.zipTomcat9.0.38 并将它们解压。

  1. 将Maven添加到环境变量中:

    ---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin

  2. 在VS Code中打开项目,在用户settings.json中添加以下代码:

    "maven.executable.path": "---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin\mvn",

  3. 按照以下图片步骤操作:

    Visual Studio Code设置用于没有主方法的Java WebApp项目。

  4. 添加Tomcat服务器并在Tomcat上运行.war文件,这里有一个GIF教程:与Tomcat一起使用

最终,您将会看到这个结果:

Visual Studio Code设置用于没有主方法的Java WebApp项目。

当您成功运行它时,可以进行调试:右键单击Tomcat服务器,然后选择调试war包

Visual Studio Code设置用于没有主方法的Java WebApp项目。

英文:

This is a Maven project which based on the concept of a project object model (POM). So first, you should download Maven and Tomcat locally.

My machine: win10, vscode1.49.0, JDK11

VS Code Extension installed: Java Extension Pack, Tomcat for java

and i download: apache-maven-3.6.3-bin.zip and Tomcat9.0.38 and extract them

  1. Add maven to Environment Variables:

    ---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin

  2. Open the project in VS Code, add the following code in User settings.json:

    "maven.executable.path": "---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin\mvn",

  3. Follow the picture steps:

Visual Studio Code设置用于没有主方法的Java WebApp项目。

  1. Add the tomcat server and run the .war on tomcat, here is a gif tutorial: work with tomcat

Finally, you will observe this result:
Visual Studio Code设置用于没有主方法的Java WebApp项目。

When you can run it successfully, debugging is achievable: right click the tomcat server and choose debug war packages:

Visual Studio Code设置用于没有主方法的Java WebApp项目。

huangapple
  • 本文由 发表于 2020年9月16日 05:24:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63910054.html
匿名

发表评论

匿名网友

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

确定