Tomcat in Intellij Idea Community Edition

2020-02-16 05:41发布

Is it possible to run a web application using Tomcat Server in Intellij Idea Community Edition?

I tried to find some information about it but haven't achived any success.

15条回答
\"骚年 ilove
2楼-- · 2020-02-16 06:10

Yes, you can use maven plugin, or simple java program. No need for IDE plugin. See for example Main class from https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat

查看更多
手持菜刀,她持情操
3楼-- · 2020-02-16 06:10

Tomcat (Headless) can be integrated with IntelliJ Idea - Community edition.

Step-by-step instructions are as below:

  1. Add tomcatX-maven-plugin to pom.xml

    <build>
        <plugins>
            <plugin>
                 <groupId>org.apache.tomcat.maven</groupId>
                 <artifactId>tomcat7-maven-plugin</artifactId>
                 <version>2.2</version>
                 <configuration>
                     <path>SampleProject</path>
                 </configuration>
            </plugin>
        </plugins>
    </build>
    
  2. Add new run configuration as below:

    Run >> Edit Configurations >> + >> Maven
    
    Parameters tab ...
    Name :: Tomcat
    Working Directory :: Project Root Directory
    Command Line :: tomcat7:run
    
    Runner tab ...
    VM Options :: <user needed options>
    JRE :: <project needed>
    
  3. Invoke Tomcat in Run/Debug mode directly from IntelliJ Run >> Run/Debug menu

NOTE: Though this is considered a hacking of using using Tomcat integration features of IntelliJ - Enterprise version features, but I would consider this a programmatic way integrating tomcat to the IntelliJ Idea - community edition.

查看更多
劳资没心,怎么记你
4楼-- · 2020-02-16 06:11

Using Maven, try tomcat7-maven-plugin:

  <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.tomcat.maven</groupId>
                  <artifactId>tomcat7-maven-plugin</artifactId>
                  <version>2.2</version>
                  <configuration>
                      <path>/</path>
                      <contextFile>src/main/webapp/WEB-INF/config/app-config.xml</contextFile>
                      <mode>context</mode>
                      <charset>UTF-8</charset>
                      <warDirectory>target/${project.artifactId}-${project.version}</warDirectory>
                  </configuration>
              </plugin>
          </plugins>
  </build>

Run it using tomcat7:run-war

More goals here

查看更多
戒情不戒烟
5楼-- · 2020-02-16 06:11
时光不老,我们不散
6楼-- · 2020-02-16 06:12

For Intellij 14.0.0 the Application server option is available under View > Tools window > Application Server (But if it is enable, i mean if you have any plugin installed)

查看更多
爷、活的狠高调
7楼-- · 2020-02-16 06:16

Intellij Community does not offer Java application server integration. Your alternatives are

  1. buying Intellij licence,
  2. switching to Eclipse ;)
  3. installing Smart Tomcat plugin https://plugins.jetbrains.com/plugin/9492
  4. installing IDEA Jetty Runner plugin https://plugins.jetbrains.com/plugin/7505
  5. running the application server from Maven, Gradle, whatever, as outlined in the other answers.

I personally installed the Jetty Runner plugin (Jetty is fine for me, I do not need Tomcat) and I am satisfied with this solution. I had to deal with IntelliJ idea - Jetty, report an exception, though.

查看更多
登录 后发表回答