Cannot start app on tomcat with intellij
Solution 1
- 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
Solution 2
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
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.
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.
Spasoje Petronijević
BY DAY: Writing Java code and learning architecture and patterns. Also I am creating my own project and hope that that I will make new "big thing". BY NIGHT: Enjoying salsa parties. (:
Updated on June 22, 2022Comments
-
Spasoje Petronijević almost 2 years
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:
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.
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.
-
Spasoje Petronijević over 7 yearsMy problem was that I was trying to use Java 1.7. Thank you for answer. Cheers. :)