Spring Boot WAR in IntelliJ

Let’s say we have a Maven Spring Boot WAR project that we want to debug as fat JAR. This works out of the box in Eclipse if we add the following dependencies:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
</dependency>

Sadly in IntelliJ this won’t work. When you try to run your application from the IDE it will crash because of missing dependencies. The problem is that the dependencies with the “provided” scope are not injected at runtime by the IDE. I consider this to be a bug, given the fact that these dependencies are marked as provided, exactly because we need them during development but they must be provided at runtime by the environment. Anyways, to fix this we can add a new profile to our POM file:

<profiles>
  <profile>
    <id>DEVEL</id>
      <dependencies>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
      </dependencies>
  </profile>
</profiles>

The newly created DEVEL profile defines the spring-boot-starter-tomcat dependency as regular dependency. Note that we can’t simply remove the “provided” scope from our default profile because that will crash the runtime environment. Our WAR should not contain spring-boot-starter-tomcat! We only need this during development.

In IntelliJ we need to activate the DEVEL profile using the Maven Projects tab, and we are good to go:

maven_spring

Lastly, if you found this post useful, please feel free to share + give it a LIKE, so others can find it too! Thanks 😊

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s