英文:
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项目。因此,首先,您应该在本地下载Maven和Tomcat。
我的电脑配置:win10,vscode1.49.0,JDK11
已安装的VS Code扩展:Java扩展包,适用于Java的Tomcat
我已下载:apache-maven-3.6.3-bin.zip和Tomcat9.0.38 并将它们解压。
-
将Maven添加到环境变量中:
---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin
-
在VS Code中打开项目,在用户settings.json中添加以下代码:
"maven.executable.path": "---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin\mvn",
-
按照以下图片步骤操作:
-
添加Tomcat服务器并在Tomcat上运行.war文件,这里有一个GIF教程:与Tomcat一起使用
最终,您将会看到这个结果:
当您成功运行它时,可以进行调试:右键单击Tomcat服务器,然后选择调试war包:
英文:
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
-
Add maven to Environment Variables:
---\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin
-
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",
-
Follow the picture steps:
- Add the tomcat server and run the .war on tomcat, here is a gif tutorial: work with tomcat
Finally, you will observe this result:
When you can run it successfully, debugging is achievable: right click the tomcat server and choose debug war packages:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论