我有一个Java Web应用程序,在我的jar文件中嵌入了Tomcat。我可以使用Docker对该应用程序进行容器化,并使用命令java -jar -myapp.jar运行它,但是我无法在Heroku中运行该容器。我尝试使用heroku CLI进行dockerize和部署,但是Heroku给我一个错误“无法访问jarfile”。
我试图通过使用heroku deploy:jar来部署胖子来解决此问题,但这错误地给了我一个错误:
load'
from /home/alec/.rbenv/versions/2.3.7/bin/bundle:22:in
我已登录Heroku,可以使用heroku auth:whoami进行验证,可以推送容器并部署它们,因此此错误没有任何意义。我使用HEROKU_DEBUG = 1重新运行,它没有返回更多信息。
我进一步尝试使用从Heroku获得的令牌在CLI中设置HEROKU_API_KEY变量,当我尝试部署jar时,这仍然导致相同的错误。
我正在使用Procfile(尽管我不确定是否有必要):
source 'http://gems.ruby-china.com'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
if RUBY_PLATFORM =~ /darwin/
gem "rmagick", "= 2.15.4" ## osx must be this version
elsif RUBY_PLATFORM =~ /linux/
gem 'simple_xlsx_reader'
gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel
gem 'pdfkit'
gem 'wkhtmltopdf-binary'
gem 'rqrcode', '~> 0.10.1'
gem 'rqrcode_png'
end
gem 'certified'
gem 'net-ssh', '2.9.1'
gem 'jenkins_api_client'
gem 'nokogiri'
end
#gem 'simple_xlsx_reader'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
gem "mysql2", "= 0.3.18"
gem 'redis-rails'
gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity', '= 0.4.5'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem 'rails', '~> 3.2'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem 'coderay', '~> 1.1.0'
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
# gem 'sunspot_solr'
# gem 'sunspot'
# gem 'progress_bar'
gem 'ansi'
gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
#rails 3.2.22.2 bug
# gem "test-unit", "~>3.0"
### profile
# gem 'oneapm_rpm'
# gem 'therubyracer'
group :development do
gem 'grape-swagger'
gem 'better_errors', '~> 1.1.0'
# gem "query_reviewer"
gem 'rack-mini-profiler', '~> 0.9.3'
if RUBY_PLATFORM =~ /w32/
gem 'win32console'
end
if RUBY_PLATFORM =~ /darwin/
gem 'puma'
end
end
group :development, :test do
if RUBY_VERSION >= '2.0.0'
gem 'pry-byebug'
gem "test-unit", "~>3.0"
end
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# Optional gem for LDAP authentication
group :ldap do
gem "net-ldap", "~> 0.3.1"
end
# Optional gem for OpenID authentication
group :openid do
gem "ruby-openid", "~> 2.1.4", :require => "openid"
gem "rack-openid"
end
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
else
warn("Please configure your config/database.yml first")
end
# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end
由于该问题似乎表明访问存在问题,因此我看不到Procfile会如何影响它。
对我来说,将不使用Spring Boot的Java Web应用程序部署到Heroku的最佳方法是什么?我已经将docker容器成功地分别部署到了Google App Engine,所以Heroku的所有工作都令人沮丧。
答案 0 :(得分:2)
我最终使用webapp-runner来部署我的应用程序以解决此问题。它运行可运行.war文件的webapp-runner jar。这需要添加heroku-maven-plugin和maven-dependency-plugin。
然后我可以添加一个Procfile:web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT
并使用Heroku CLI使用git添加应用程序。与webapp-runner的链接是使用webapp-runner部署tomcat Java应用程序的指南。