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条回答
戒情不戒烟
2楼-- · 2020-02-16 06:17

Yes, its possible and its fairly easy.

  1. Near the run button, from the dropdown, choose "edit configurations..."
  2. On the left, click the plus, then maven and rename it "Tomcat" on the right side.
  3. for command line, enter "spring-boot:run"
  4. Under the runner tab, for 'VM Options', enter "-XX:MaxPermSize=256m -Xms128m -Xmx512m -Djava.awt.headless=true" NOTE: 'use project settings' should be unticked.
  5. For environment variables enter "env=dev"
  6. Finally, click Ok.

When you're ready to press run, if you go to "localhost:8080/< page_name > " you'll see your page.

My pom.xml file is the same as the Official spring tutorial Serving Web Content with Spring MVC

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-serving-web-content</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
查看更多
▲ chillily
3楼-- · 2020-02-16 06:17

I used Jay Lin's answer. Highly recommend it.

If you never used Maven before and don't want to go deep into it: follow Jay Lin's answer, but also do this:

  1. right click on your project name -> Add Framework support -> Maven.

  2. Then install maven from here http://maven.apache.org/install.html. Do what it says, run the commands.

  3. Then install spring-boot from here https://mvnrepository.com.

  4. Then follow the error messages if there are any - maybe you would need to install some other stuff (just google it and that mvnrepository.com would come up). To install use this command:

    mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path

replace path with where you downloaded the jar file, replace version, group and artifact id with info from mvnrepository.com.

  1. Further errors I encountered:

I had to create a class in src/main/java (with simple System.out.println command in main) and add <start-class>main.java.Hello</start-class> in <properties> tag in pom.xml. Btw, the pom.xml should appear itself when you do the first action from my answer - copy paste Jay Lin's code there.

Another error I got was connected to JAVA_HOME variable and the verion stuff. Somewhy it thought jdk is 7th version and I was telling it was 8th. So I changed the java version tag in <properties> to this <java.version>1.7</java.version>.

Now it works fine! Good luck everyone.

查看更多
小情绪 Triste *
4楼-- · 2020-02-16 06:22

If you are using maven, you can use this command mvn tomcat:run, but first you add in your pom.xml this structure into build tag, just like this:

<build>
    <finalName>mvn-webapp-test</finalName>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>${maven.compiler.plugin.version}</version>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
              </configuration>
          </plugin>
      </plugins>
  </build>
查看更多
该账号已被封号
5楼-- · 2020-02-16 06:26

If you use Gradle, you can try my script: https://github.com/Adrninistrator/IDEA-IC-Tomcat .This script will build files for web application, create a Tomcat instance, start Tomcat and load the web application.

查看更多
Lonely孤独者°
6楼-- · 2020-02-16 06:26
VM :-Djava.endorsed.dirs="C:/Program Files/Apache Software Foundation/Tomcat 8.0/common/endorsed" 
    -Dcatalina.base="C:/Program Files/Apache Software Foundation/Tomcat 8.0"  
    -Dcatalina.home="C:/Program Files/Apache Software Foundation/Tomcat 8.0" 
    -Djava.io.tmpdir="C:/Program Files/Apache Software Foundation/Tomcat 8.0/temp" 
    -Xmx1024M
查看更多
成全新的幸福
7楼-- · 2020-02-16 06:27

Tomcat can also be integrated with IntelliJ Idea - Community Edition with Tomcat Runner Plugin.

Details below: https://plugins.jetbrains.com/plugin/8266-tomcat-runner-plugin-for-intellij

查看更多
登录 后发表回答