从IntelliJ导出WAR包部署到Heroku遇应用错误求助
First things first—let’s get the actual error details instead of guessing. Heroku’s generic "Application error" message doesn’t tell us much, so run this command to pull your app’s live logs:
heroku logs --tail --app <app-name>
This will show you the exact stack trace or failure reason, which is critical for narrowing down the issue. Since you suspect IntelliJ’s WAR export is the culprit, let’s focus on that angle first:
Common IntelliJ WAR Export Issues & Fixes
- Missing runtime dependencies: IntelliJ’s artifact configuration sometimes excludes certain runtime libraries by default. To fix this:
- Go to
File > Project Structure > Artifacts - Select your WAR artifact, then check the
Available Elementspane - Ensure all required libraries (like database drivers, framework JARs) are added to the
WEB-INF/libfolder of the artifact - Re-export the WAR and redeploy
- Go to
- Incorrect environment configuration: If your app uses environment-specific config files (like
application-dev.propertiesvsapplication-prod.properties), IntelliJ might be packaging the dev version instead of the one compatible with Heroku. Double-check your artifact settings to make sure the production config is included, and verify that Heroku’s environment variables (likeDATABASE_URL) are correctly referenced in your config. - JDK version mismatch: Heroku uses a default Java version (often 8 or 11) that might not match what you’re using in IntelliJ. To align them:
- Create a
system.propertiesfile in your project root - Add a line like
java.runtime.version=17(replace with your local JDK version) - Commit this file to your repo and redeploy
- Create a
- Corrupted build cache: IntelliJ’s build cache can sometimes produce faulty WARs. Try:
- Running
Build > Clean Project - Deleting the existing artifact (
Project Structure > Artifacts > Delete) - Re-creating the WAR artifact from scratch
- Exporting and redeploying the fresh WAR
- Running
Quick Validation Step
Before redeploying, extract your IntelliJ-exported WAR file locally and compare the WEB-INF/lib folder with the libraries your local Tomcat uses to run the app. If any critical JARs are missing in the WAR, that’s almost certainly the problem.
If after checking all these the issue persists, share the specific error lines from your Heroku logs—we can dig deeper from there!
内容的提问来源于stack exchange,提问作者Stefano Ferrario

