Few days ago, when I deployed a Spring MVC app to Heroku, I've encountered some problems, I must spent a lot of time and effort to fix it. If you currently use Intellij IDEA to code, use Spring MVC for backend, use Maven to manage dependencies, use Java 11 and you want to deploy your app to Heroku, this article is for you. In this post, I will share somethings that you need to be careful with.
https://devcenter.heroku.com/articles/java-webapp-runner
2. If you use Intellij, you must notice that you cannot run following command
Why? What is the reason? The reason quiet simple, there is no dependency folder inside target folder. So, it means that target/dependency/webapp-runner.jar is not existed.
3. If you open the target folder which is created when you build your project, there is no dependency folder inside the target folder.
4. So, how to make the dependency folder appears? I must spend a lot of effort to discover one simple thing. You should open your POM.xml file, and you must see the <pluginManagement> tag. Now, you get back to the article of Heroku at step 1, you might notice that there is no <pluginManagement> in their code.
This is code from Heroku team, you should look at it carefully
Then I found a document of pluginManagement from Maven:
5. So, everything you need to do is delete the tag <pluginManagement> and keep the content inside it.
Now, every time you build you project, Maven will download all your plugin. I cost more time to build your project. And, inside the target folder, there must an dependency folder existed.
https://devcenter.heroku.com/changelog-items/1489
2. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project CandidateManagement: Fatal error compiling: error: invalid target release: 11
Our project use Java version 11, then, in pom file, the configuration of maven-compier-plugin is:
Then your project cannot be build, I found that just replace
<target>11</target>
with
everything will go fine.
I still don't know what is reason behind it.
I. The first problem
1. First of all, you need to read this article and follow the instructionshttps://devcenter.heroku.com/articles/java-webapp-runner
2. If you use Intellij, you must notice that you cannot run following command
java -jar target/dependency/webapp-runner.jar target/*.war
Why? What is the reason? The reason quiet simple, there is no dependency folder inside target folder. So, it means that target/dependency/webapp-runner.jar is not existed.
3. If you open the target folder which is created when you build your project, there is no dependency folder inside the target folder.
4. So, how to make the dependency folder appears? I must spend a lot of effort to discover one simple thing. You should open your POM.xml file, and you must see the <pluginManagement> tag. Now, you get back to the article of Heroku at step 1, you might notice that there is no <pluginManagement> in their code.
You might see the <pluginManagement> in your pom.xml |
Code from Heroku team, You can see that there is no <pluginManagement> tag |
Then I found a document of pluginManagement from Maven:
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.pluginManagement is way to share your same plugin configuration among several project
5. So, everything you need to do is delete the tag <pluginManagement> and keep the content inside it.
Now, every time you build you project, Maven will download all your plugin. I cost more time to build your project. And, inside the target folder, there must an dependency folder existed.
II. The second problem:
1. If you use java 11, you should read this article:https://devcenter.heroku.com/changelog-items/1489
2. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project CandidateManagement: Fatal error compiling: error: invalid target release: 11
Our project use Java version 11, then, in pom file, the configuration of maven-compier-plugin is:
Then your project cannot be build, I found that just replace
<source>11</source>
<target>11</target>
with
<release>11</release>
everything will go fine.
I still don't know what is reason behind it.
Comments
Post a Comment
» Vui lòng không spam vì nó sẽ bị xóa ngay sau đó.
» Nếu chèn code hãy mã hóa trước khi chèn vào nhận xét.
» Nếu thủ thuật Blog không áp dụng được thì hãy để lại URL blog để mình tiện kiểm tra.