java 无法使用 intellij 在 tomcat 上启动应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41450629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot start app on tomcat with intellij
提问by Spasoje Petronijevi?
I am trying to run my web app with IDEA intellij and tomcat server. I downloaded tomcat server, paste it in program files, made CATALINA_HOME and edit path to %CATALINA_HOME%\bin; . My run config:
我正在尝试使用 IDEA intellij 和 tomcat 服务器运行我的网络应用程序。我下载了 tomcat 服务器,将其粘贴到程序文件中,制作了 CATALINA_HOME 并编辑了 %CATALINA_HOME%\bin 的路径;. 我的运行配置:
When I start tomcat server from bin/startup.bat and try to run project I got error Error running event: Address localhost:8080 already in use.
当我从 bin/startup.bat 启动 tomcat 服务器并尝试运行项目时,出现错误 Error running event: Address localhost:8080 already in use。
When I don't start tomcat with bat file first I got an error: Application server was not connected before run configuration stop, reason: Unable to ping server at localhost:1099. When I run that bat script from tomcat and go to localhost:8080 i see tomcat start window.
当我没有先用 bat 文件启动 tomcat 时,出现错误:在运行配置停止之前未连接应用程序服务器,原因:无法在 localhost:1099 上 ping 服务器。当我从 tomcat 运行那个 bat 脚本并转到 localhost:8080 时,我看到了 tomcat 启动窗口。
回答by JimHawkins
- check if you're using JDK 8 with Tomcat 9
- in your "Run Configuration", go to the tab "Deployment" and ensure that you've selected the correct war and chose a deployment path. For convenience, add the deployment path to the URL in the "After launch" section on the tab "Server"
- in your screenshot, on the tab "Server", I see there is no action defined in the section "Before launch". Did you delete it? By default, there are two entries like
Build
andBuild 'simpleServlet:war' artifact
. Add these entries by clicking on+
- before you start your web app via IntelliJ, ensure that Tomcat isn't running: open a browser and enter the URL
http://localhost:8080
. There must be an error message "no connection" or similar. If you see the welcome page, stop Tomcat. - run your application via IntelliJ
- 检查您是否将 JDK 8 与 Tomcat 9 一起使用
- 在您的“运行配置”中,转到“部署”选项卡并确保您选择了正确的War并选择了部署路径。为方便起见,将部署路径添加到“服务器”选项卡上“启动后”部分的 URL 中
- 在您的屏幕截图中,在“服务器”选项卡上,我看到“启动前”部分中没有定义任何操作。你删除了吗?默认情况下,有两个条目,如
Build
和Build 'simpleServlet:war' artifact
。通过单击添加这些条目+
- 在通过 IntelliJ 启动 Web 应用程序之前,请确保 Tomcat 未运行:打开浏览器并输入 URL
http://localhost:8080
。必须有“无连接”或类似的错误消息。如果您看到欢迎页面,请停止 Tomcat。 - 通过 IntelliJ 运行您的应用程序
回答by code_disciple
I've been struggling with this as a new developer and I find it's easiest when someone starts from scratch. My current version of IntelliJ is 2017.1.4. Using Tomcat 9.0.0
作为一名新开发人员,我一直在努力解决这个问题,我发现当有人从头开始时,这是最容易的。我当前的 IntelliJ 版本是 2017.1.4。使用 Tomcat 9.0.0
File -> New Project -> Java -> check "Web Application" -> Name it and then Finish. Your current project directory should contain [.idea + src + web/WEB-INF] with a default index.jsp in the web directory and a web.xml in the WEB-INF directory. This step does a lot of the setup for you. This should also make steps 2 and 3 pointless.
Under File -> Settings -> Facets, check if a Web Resource Directory exists (should point towards your web directory of your current project directory). If one doesn't, add one by hitting: + -> Web -> double-click resource directory to create.
Under File -> Settings -> Artifacts, check if a "ProjectName:war exploded" exists. If not, create one by hitting: + -> Web Application: Exploded -> From Modules -> Select and Confirm your Project Folder.
Next to the Run button in the top-right there should be a downward arrow for "Edit Configurations". Click that -> Edit Configurations -> + -> Tomcat Server -> Local. Under the Server tab, hit Configure and point to your Tomcat base directory (Ex: Tomcat 9.0.0.M22). Under Deployment Tab, hit: + -> Artifact -> "ProjectName:war exploded".
Add something to your index.jsp so that you can actually see a result and hit run. It should automatically open your browser to your index.jsp page.
文件 -> 新建项目 -> Java -> 勾选“Web 应用程序” -> 命名,然后完成。您当前的项目目录应该包含 [.idea + src + web/WEB-INF],在 web 目录中有一个默认的 index.jsp,在 WEB-INF 目录中有一个 web.xml。这一步为您做了很多设置。这也应该使第 2 步和第 3 步变得毫无意义。
在 File -> Settings -> Facets 下,检查是否存在 Web 资源目录(应指向当前项目目录的 Web 目录)。如果没有,请通过点击添加一个:+ -> Web -> 双击资源目录创建。
在文件 -> 设置 -> 工件下,检查是否存在“项目名称:War爆炸”。如果没有,请点击:+ -> Web Application: Exploded -> From Modules -> 选择并确认您的项目文件夹来创建一个。
在右上角的“运行”按钮旁边应该有一个“编辑配置”的向下箭头。单击它 -> 编辑配置 -> + -> Tomcat 服务器 -> 本地。在服务器选项卡下,点击配置并指向您的 Tomcat 基本目录(例如:Tomcat 9.0.0.M22)。在部署选项卡下,点击:+ -> Artifact -> "ProjectName:war purged"。
向您的 index.jsp 添加一些内容,以便您可以实际看到结果并点击运行。它应该会自动将您的浏览器打开到您的 index.jsp 页面。
Normally you would have to configure your web.xml to your servlet class or use the welcome-file tags to specify which default pages to look for but index.html/index.jsp are defaults. So if you name your .jsp differently you will require additional configuration in your web.xml.
通常,您必须将 web.xml 配置为 servlet 类或使用欢迎文件标签来指定要查找的默认页面,但 index.html/index.jsp 是默认页面。因此,如果您以不同的方式命名 .jsp,您将需要在 web.xml 中进行额外配置。