warbler icon indicating copy to clipboard operation
warbler copied to clipboard

Adding other paths to LOAD_PATH in nogemspec trait

Open jbarreneche opened this issue 13 years ago • 3 comments

Hi, I'm using warbler to build a jar for a standalone application (thus, nogemspec) and I'd like to have other paths (apart from lib/) to be included in the $LOAD_PATH.

The trait "Warbler::Traits::NoGemspec", doesn't have any configuration to include other paths than lib/. I'm thinking of making a pull request that adds it, but I'd like some insight if you are interested in the feature and if you have any preference for the config name.

Thanks!

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1446642-adding-other-paths-to-load_path-in-nogemspec-trait?utm_campaign=plugin&utm_content=tracker%2F136961&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136961&utm_medium=issues&utm_source=github).

jbarreneche avatar Sep 12 '12 12:09 jbarreneche

This sounds like exactly what I am looking for! I need to add a 'components' directory to $LOAD_PATH. I would be interested in your fork. Thanks

ryanrolland avatar Jul 21 '16 00:07 ryanrolland

Hi, we monkeypatched Warbler::Traits::NoGemspec

I'm not completely sure if this works with newer versions of warbler or newer versions of jruby, but this is what our patch looks like:

## Make warbler include jars in loadpath
# https://github.com/jruby/warbler/issues/111
require 'warbler/traits/nogemspec'
class Warbler::Traits::NoGemspec
  def after_configure
    add_init_load_path(config.pathmaps.application.inject("lib") {|pm,x| pm.pathmap(x)})
    add_init_load_path(config.pathmaps.application.inject("jars") {|pm,x| pm.pathmap(x)})
  end
end

Sorry I can't be of any more help, the issue it's a bit old and I don't remember much of the whole problem.

jbarreneche avatar Jul 21 '16 11:07 jbarreneche

Thanks for feedback! I was a little confused earlier in that I am working with a Rails 3.0.20 app and the traits that are executed for me are:

  • Warbler::Traits::War
  • Warbler::Traits::Rails
  • Warbler::Traits::Bundler (so no "nogemspec" trait execution)

I was able to get my app running under jetty (executable war) by modifying the $LOAD_PATH directly in application.rb: $LOAD_PATH.unshift(Rails.root)

I am thinking this is sort of a hack. It seems like you should be able to add this path directly from your warble.rb or Gemfile? Perhaps this is what the "Bundler 'path' components" are suppose to enable (line 65-73 in traits/bundler.rb)?

ryanrolland avatar Jul 21 '16 18:07 ryanrolland