15

Without using maven, to run the app on tomcat from the Intellij IDE, all you have to do is create an artifact and a "tomcat" run configuration pointing to that artifact, this way you can see tomcat output, restart the server, and other stuff right in the IDE.

Now using maven, there's no need to create an artifact, because maven already does the compiling, packaging, etc.

I know i can deploy it using the command mvn tomcat7:redeploy but this way i can't see standart output/errors and debug. So what is the standard way to run the app from IntelliJ without having to create an artifact?

Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101

3 Answers3

10

In pom.xml add

<build>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <uriEncoding>UTF-8</uriEncoding>
                    <path>/your-path</path>
                    <update>true</update>
                </configuration>
            </plugin>
</build>

In IntelliJ, open Menu > View > Tool Windows > Maven Projects

Plugins > tomcat7 > tomcat7:run
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • Thanks it worked, i upvoted your answer but i checked Amilas' as accepted cause that way i don't have to declare a maven plugin. – Mateus Viccari Aug 18 '15 at 12:29
6

If you have set

<packaging>war</packaging>

in your pom, IDEA should automatically identify the artifact (your WAR file) to deploy. No need to manually create an artifact.

Amila
  • 5,195
  • 1
  • 27
  • 46
  • I already have this set, but if i try to create a run/debug configuration for tomcat server, it keeps saying "Warning: No artifacts configured". Maybe i should use another type of run/debug configuration instead of tomcat, but which one? – Mateus Viccari Aug 17 '15 at 19:14
  • "tomcat server" is the correct type. Just go to "deployment" tab in the run/debug configuration and click the plus icon to add your maven artifact. – Amila Aug 17 '15 at 19:18
  • The only option i have when clicking the "Plus" icon is "External source", there's no maven artifact there – Mateus Viccari Aug 17 '15 at 19:25
  • 1
    Do you have a paid IntelliJ subscription? I don't think you can deploy without it. – Craig Aug 17 '15 at 19:33
  • My fault, intellij always create an artifact based on maven, i think i deleted it before cause now i made some changes in pom.xml and the artifact was created again. Now i can deploy it normally. – Mateus Viccari Aug 18 '15 at 12:21
3

When you setup this: n IntelliJ, open Menu > View > Tool Windows > Maven Projects, you will see this menu:

enter image description here

When you click on this picture you can enter the goal of Maven, for example tomcat7:run