0

I try to make a .JAR from a simple ruby sample. In MRI and jRuby i can run this without problem but when i try to warble the project i get error when i run the JAR file.

Errno::ENOENT: No such file or directory - configuration.yml

The configuration.yml file is not in the project folder because is needs to be editable so shouldn't be in the JAR included, optimally the path would be relative to the jar so that the YML file is in the same folder as the JAR file. So how could i do this ?

My bin\sample.rb

require 'yaml'
@conf = YAML::load_file "c:/test/configuration.yml"
#@conf = YAML::load_file "c:\\test\\configuration.yml"
puts @conf['username']

My c:\test\configuration.yml

username: test

My .gemspec file

Gem::Specification.new do |spec|
  spec.require_paths << '.'
}

My config\warble.rb

Warbler::Config.new do |config|
  config.jar_name = "sample"
end

I warble with "warble jar -trace" and get no errors I use jruby-1.7.4 and warbler-1.3.8.

Wooble
  • 87,717
  • 12
  • 108
  • 131
peter
  • 41,770
  • 5
  • 64
  • 108

1 Answers1

0

Figured it out without using java as some solutions on the web suggest (but not for warble).

require 'yaml'

scriptpath = __FILE__[/(.*)\/.+\.jar!/]
yamlpath   = "#{$1[6..-1]}/configuration.yml"
@conf      = YAML::load_file(yamlpath)
puts @conf['username']
# => test
peter
  • 41,770
  • 5
  • 64
  • 108