Unable to run Springboot application in Intellij
Answered
'HI, I am trying to run Spring boot application using Intellij Idea. I have the application.yaml file which I don't want to include in the fat JAR file. So I modified the POM.xml file and given below settings
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.yaml</exclude>
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
But when I am trying to run the application from Idea, it is not able run the application becase the application.yaml file is not present inside JAR. How do I achieve the goal of excluding the application.yaml file iside jar as well as able to run my app in IntelliJ.
Please sign in to leave a comment.
IntelliJ IDEA uses the same configuration as Maven. You can try using different profiles in Maven, one for development in IntelliJ IDEA and another for production build.
Thanks for your prompt response. Can you please let me know how to set multiple profile for Maven using IDEA, one for development in IntelliJ IDEA and another for production build? Thanks.
You set it in Maven by editing your pom.xml. IntelliJ IDEA will show the profiles available in your build and you will be able to switch between them using the checkboxes.
Thanks @Serge. I got you.
@Serge, I am able to mention 2 profiles in pom.xml file. Also selecting one profile I can do, clean, install, test etc. But how to run my pspring boot services? I didn't find any option of selecting profile while running the main class. Please help
Profile is selected and used when the project is imported. You can switch it in the Maven Projects tool window and it will be used by run configurations.
For production builds you can run Maven tasks with a different profile:
Hi @Serge, I edited my pom.xml as below to have 2 profiles i.e. test & prod. I wanted to exclude application.yaml file from "prod" profile. So that this file wont be bundled with jar. Whereas in "test" profile I want to include that application.yaml so that I can run from IntelliJ IDEA. Please check the screenshot below how I am setting the profile, as per my settings my application should fail to run. But it is running fine. So my assumption is setting of profile is not working properly.
`-` prefix disables the profile. Also, you are using Spring Boot run/debug configuration, while my screenshot is for Maven Run/debug configuration:
https://www.jetbrains.com/help/idea/run-debug-configuration-maven.html.
Spring profiles are not Maven profiles: https://stackoverflow.com/questions/39738901/how-do-i-activate-a-spring-boot-profile-when-running-from-intellij.
Thanks for your response. I got you now. I created a Maven run configuration for my project. Actually my goal is to run the application as spring-boot application, so also created spring boot run configuration. Now when I run the application as spring boot how can I mention to use that maven profile
I apologize for long conversation regarding this. Actually I am newbie to IntelliJ IDEA :-(
You need to select it as an active Maven profile in the Maven Projects tool window and reimport the project so that IntelliJ IDEA uses this profile, while for production you will run the Maven goal with a different profile specified in the Maven run/debug configuration parameters.