140

Using Netbeans, I develop sites with Tomcat as the local server to manage it. In Netbeans it was "Install, write hit Run and it works" How do I pull the same thing off in IntelliJ?

I can't find step-by-step instructions for this.

Jag
  • 1,840
  • 1
  • 17
  • 25
Mantar
  • 2,710
  • 5
  • 23
  • 30
  • Which version of IntelliJ are you using? – Romain Linsolas Oct 28 '10 at 09:21
  • I'm using IntelliJ 9.0.3 – Mantar Oct 28 '10 at 09:23
  • Related: [IntelliJ Tomcat Server plugin fails to auto-populate my empty external Tomcat `base` folder](https://stackoverflow.com/q/45477139/642706) – Basil Bourque Jan 07 '18 at 04:51
  • See IntelliJ Ultimate edition "Help": [Run/Debug Configuration: Tomcat Server](https://www.jetbrains.com/help/idea/run-debug-configuration-tomcat-server.html) – Basil Bourque Jan 07 '18 at 04:53
  • FYI, you can run [Jetty](https://en.wikipedia.org/wiki/Jetty_(web_server)) from within IntelliJ, then later deploy to Tomcat. For a preconfigured example, try a Vaadin starter web app, choosing the "Plain Java Servlet" flavor. As a Maven-driven project, you can simply unzip the downloaded file, then have IntelliJ open the folder as a project. In the IntelliJ `Maven` panel, expand the `Plugins` item to reveal the `Jetty` item, in which you will find `jetty:run` item. You may be able to study the POM file to learn how to configure such a Jetty engine within your own project. – Basil Bourque Oct 07 '19 at 03:16
  • See: [*Setting up and Working with Apache Tomcat in IntelliJ IDEA Ultimate*](https://foojay.io/today/setting-up-and-working-with-apache-tomcat-in-intellij-idea-ultimate/) by Helen Scott of JetBrains, 2022-05. And see the documentation [here](https://www.jetbrains.com/help/idea/application-servers-support.html) and [here](https://www.jetbrains.com/help/idea/run-debug-configuration-tomcat-server.html). And see [*Tomcat in IntelliJ IDEA Ultimate*](https://youtu.be/ThBw3WBTw9Q) on YouTube 2022-03, by Dalia Abo Sheasha of JetBrains. – Basil Bourque Nov 24 '22 at 00:29

7 Answers7

120

NOTE: Community Edition doesn't support JEE.

First, you will need to install a local Tomcat server. It sounds like you may have already done this.

Next, on the toolbar at the top of IntelliJ, click the down arrow just to the left of the Run and Debug icons. There will be an option to Edit Configurations. In the resulting popup, click the Add icon, then click Tomcat and Local.

From that dialog, you will need to click the Configure... button next to Application Server to tell IntelliJ where Tomcat is installed.

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50
  • 1
    Hi Steven. I followed these directions but I don't know how to configure the facets and artifacts correctly. I found no way to generate a war that won't result in a 404 error because index.gsp isn't handled by grails. Could you please add some instructions regarding facets and artifacts or advise under http://stackoverflow.com/questions/20053061/intellij-deploying-grails-app-to-tomcat-always-results-in-http-404 - thanks. – HAL 9000 Nov 19 '13 at 16:25
  • 5
    can't see Application server under Bulid, Execution and Deployment. – Pankaj Nimgade Mar 13 '16 at 10:44
  • 1
    well shit. ive spent 2.5 days watching youtube tutorials trying to figure out how in the hell to make intellij recognize i have javaEE so i can make a damn servlet. ugh. good answer. – Ungeheuer Oct 09 '16 at 06:16
  • 1
    When I point the config to a Tomcat 'base' directory outside of the Tomcat folder, I get error complaining there is no `conf` folder. I create one, then I get an error there is no `server.xml` file. With NetBeans, all that stuff for the `base` directory was automatically created in the empty folder I’d created. – Basil Bourque Apr 16 '17 at 10:56
  • @BasilBourque When you download and unzip Tomcat, it will come with a conf folder and all configurations already. If you don't have that then you didn't download a valid Tomcat distribution or you pointed IntelliJ to the wrong location. – Steven Benitez Nov 15 '18 at 20:53
  • @StevenBenitez Reread my first sentence. I am directing IntelliJ to use a folder outside Tomcat as the [Catalina “base” folder](https://tomcat.apache.org/tomcat-9.0-doc/introduction.html). While NetBeans knows how to setup that external base folder automatically, IntelliJ does not. The solution is to copy that `conf` folder to which you refer from the Tomcat folder and paste into the external base folder. Then all is well and IntelliJ can run Tomcat with an external base folder. – Basil Bourque Nov 15 '18 at 20:59
  • 1
    Note: Under the build configuration, in the Deployment tab, there is information at the bottom called `Application Context`. This is the directory the local tomcat uses, so if it says `asdf`, your servlet resides at `localhost:8080/asdf` - this can differ from production, which is what confused me – lucidbrot Jan 30 '19 at 09:35
  • Tomcat is not a JEE application server, it's a servelet container. – danieltc07 Mar 18 '22 at 15:22
51

Here is step-by-step instruction for Tomcat configuration in IntellijIdea:

1) Create IntellijIdea project via WebApplication template. Idea should be Ultimate version, not Community edition

enter image description here

2) Go to Run-Edit configutaion and set up Tomcat location folder, so Idea will know about your tomcat server enter image description here

3) Go to Deployment tab and select Artifact. Apply enter image description here

4) In src folder put your servlet (you can try my example for testing purpose) enter image description here

5) Go to web.xml file and link your's servlet like this

enter image description here

6) In web folder put your's .jsp files (for example hey.jsp)

enter image description here

7) Now you can start you app via IntellijIdea. Run(Shift+F10) and enjoy your app in browser:

- to jsp files: http://localhost:8080/hey.jsp (or index.jsp by default)

- to servlets via virtual link you set in web.xml : http://localhost:8080/st

Aconic
  • 737
  • 8
  • 4
  • In your step 3, I don't have the "Artifact" item, only the "External Source" item. Do you know what is wrong? – Nicolas S.Xu Jun 25 '16 at 15:37
  • Unfortunately, no – Aconic Feb 06 '17 at 12:11
  • @NicolasS.Xu I had the same problem when I had just made a normal project. If you make a project using the WebApplication template (as in step 1), it should appear. – user1339253 Aug 10 '17 at 13:17
  • It's possible to do this with the Community Edition, links: https://www.shortn0tes.com/2017/01/tutorial-intellij-idea-community.html and https://benkiew.wordpress.com/2017/06/04/idea-build-your-own-tomcat-integration-for-the-free-intellij-idea-community-edition/, but for the price, if you're serious about developing web applications, Ultimate gives you a lot more value including for Jersey/ReST, JSP, JSF, etc. Why use a handsaw to rip the sheet when for little money, you can get a fine tablesaw? – Russ Bateman May 04 '18 at 15:19
  • @NicolasS.Xu the thing is not in project template. To be able add some artifact you need first to have artifact defined. To do it - go to Project Structure > Artifacts > Add WAR - create there META-INF and WEB-INF - put web.xml and compile output. Compile output should be inside classes directory After all you will be able to add this new WAR to your Run Configuration artifacts – Александр М Nov 09 '22 at 17:24
  • @user1339253 the thing is not about project template, so – Александр М Nov 09 '22 at 17:24
43

Which version of IntelliJ are you using? Note that since last year, IntelliJ exists in two versions:

  • Ultimate Edition, which is the complete IDE
  • Community Edition, which is free but does not support JavaEE developments.

(see differences here)

In case you are using the Community Edition, you will not be able to manage a Tomcat installation.

In case you are using the Ultimate Edition, you can have a look at:

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273
  • I looked at it (Using ultimate btw) and it says go to Project Structure -> Modules -> Add new Facet. Which gives me *one* option, Flex... :/ – Mantar Oct 28 '10 at 09:34
  • That could be related to the project being an "Unknown Module" whatever that means. I suppose. But even so if I make a new project I'll find more options there but not TOmcat.. – Mantar Oct 28 '10 at 09:40
  • @Meke Did you had a look here: http://www.jetbrains.com/idea/features/application_server.html ? – Romain Linsolas Oct 28 '10 at 10:03
  • I saw that yes, but it doesn't tell me anything about how to actually do it which is the confusion here. Will I have to download tomcat myself, which I didn't do with Netbeans or can IntelliJ handle it itself..? – Mantar Oct 28 '10 at 10:44
  • So all in all, you have no idea then. – Mantar Oct 28 '10 at 11:35
23

You can also debug tomcat using the community edition (Unlike what is said above).

Start tomcat in debug mode, for example like this: .\catalina.bat jpda run

In intellij: Run > Edit Configurations > +

Select "Remote" Name the connection: "somename" Set "Port:" 8000 (default 5005)

Select Run > Debug "somename"

MartinM
  • 331
  • 2
  • 3
  • Excellent. You can also set up an external tool to start Tomcat from within IntelliJ IDE. In Settings::Tools::External Tools, set program field as path to your catalina.bat, set parameters field to jpda run. Save it. The tool will be available in menu Tools::External Tools. Note the use of Tomcat connector port 8000, stated above. If you change that port in Tomcat's server.xml, then also change it in intelliJ's remote connection definition. – J Slick Nov 11 '15 at 01:59
13

Please verify that the required plug-ins are enabled in Settings | Plugins, most likely you've disabled several of them, that's why you don't see all the facet options.

For the step by step tutorial, see: Creating a simple Web application and deploying it to Tomcat.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • On the confluence site of IntelliJ IDEA this tutorial has sadly disappeared. Only a reference to a Russian tutorial is present in the comments. – Jan Croonen Jul 13 '15 at 20:02
5

The problem I had was due to the fact that I was unknowingly editing the default values and not a new Tomcat instance at all. Click the plus sign at the top left part of the Run window and select Tomcat | Local from there.

damd
  • 6,116
  • 7
  • 48
  • 77
1

In Netbeans you can right click on the project and run it, but in IntelliJ IDEA you have to select the index.jsp file or the welcome file to run the project.

this is because Netbeans generate the following tag in web.xml and IntelliJ do not.

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Ammar Bozorgvar
  • 1,230
  • 19
  • 30