You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Heroku平台同时部署.jar文件与.properties文件?

Deploying JAR and Properties Files to Heroku

Got it, let's work through getting both your server.jar and server.properties deployed to Heroku properly. The heroku deploy:jar command only uploads the specific JAR you specify, which is why your properties file didn't come along for the ride. Here are two reliable, common approaches to fix this:

Option 1: Package the Properties File Into Your JAR

If you don't mind bundling your config directly with the application, this is the simplest method. Most Java build tools (Maven, Gradle) automatically include files from the src/main/resources directory in the final JAR.

  • For Maven projects:

    1. Move your server.properties into the src/main/resources folder of your project.
    2. Rebuild your JAR with mvn clean package—this embeds the properties file inside the JAR.
    3. Deploy as before with heroku deploy:jar server.jar --app myapp.
    4. In your code, read the properties file using the classpath (e.g., getClass().getResourceAsStream("/server.properties")).
  • For Gradle projects:

    1. Place server.properties in src/main/resources.
    2. Run ./gradlew build to generate the JAR with the embedded config.
    3. Deploy using the same heroku deploy:jar command.

Option 2: Deploy via Git (Keep JAR and Properties Separate)

If you want to keep the JAR and properties file separate (maybe for easier config updates without rebuilding the JAR), use Git to deploy all files together.

  1. Create a new empty directory on your local machine.
  2. Copy your server.jar and server.properties into this directory.
  3. Create a Procfile (no file extension) in the same directory. Add a line defining how to start your app—adjust the command to match how your app reads the properties file:
    web: java -jar server.jar --config=server.properties
    
    Note: Replace --config=server.properties with the actual argument your application expects to load the properties file.
  4. Initialize a Git repo in this directory:
    git init
    git add .
    git commit -m "Add JAR and config file"
    
  5. Link the repo to your Heroku app:
    heroku git:remote -a myapp
    
  6. Deploy to Heroku:
    git push heroku main
    

Heroku will detect the Procfile and deploy all files in your repo, including the properties file.

Quick Notes

  • If you previously used heroku deploy:jar, switching to Git deployment will overwrite the existing app on Heroku—this is expected behavior.
  • If your server.properties contains sensitive data (like API keys), consider using Heroku's config vars instead (set them with heroku config:set KEY=value and read them as environment variables in your code) to avoid committing sensitive info to Git.

内容的提问来源于stack exchange,提问作者Maximax67

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 11:39:09