Skip to content

Instantly share code, notes, and snippets.

@mkristian
Created June 7, 2016 09:04
Show Gist options
  • Save mkristian/52f1116aff149d7ea30e936221284e36 to your computer and use it in GitHub Desktop.
Save mkristian/52f1116aff149d7ea30e936221284e36 to your computer and use it in GitHub Desktop.
$ gem install ruby-maven
$ rmvn package
$ java -jar pkg/*.jar ./myscript.rb
packaging :jrubyJar
gemfile
jarfile
# fixes some weird dependency problem
jar 'log4j:log4j:1.2.17'
resource :includes => ['myscript.rb']
@aviflax
Copy link

aviflax commented Jun 7, 2016

hi @mkristian, thanks so much for this!

Just a few questions if you don’t mind…

  • Do I need to understand Maven in order to understand the Mavenfile?
  • Where can I find docs on the resource directive?
  • Does the resource directive copy the specified paths into the JAR file? If so, where does it put them? Does it support directories?
    • I’ve tried putting both directories and paths to scripts into this array but I don’t see them ending up in the JAR. And if they don’t end up in the JAR, what’s the point of specifying them here?

Thank you!

@aviflax
Copy link

aviflax commented Jun 7, 2016

Ah, I found some docs on resource so I think I see what I need to try… will report back. Thanks!

@aviflax
Copy link

aviflax commented Jun 8, 2016

@mkristian, I’m having some trouble with this section of my Mavenfile:

resource directory: '.',
         excludes: ['coverage', 'doc', 'migrations', 'pkg', 'script', 'test']

Those dirs are just not getting excluded; in fact the pkg dir is included and it’s making the JAR file massive… anything obvious I’m doing wrong here?

Thank you!

@aviflax
Copy link

aviflax commented Jun 8, 2016

@mkristian, ah, never mind, I finally figured it out, I think, maybe sorta. Currently this is working for me:

resource directory: '.',
         includes: ['bin/**/*.*', 'lib/**/*.*'],
         excludes: ['pkg/**/*.*']

Thanks!

@aviflax
Copy link

aviflax commented Jun 8, 2016

@mkristian actually I am still having one last problem… lol sorry to keep bugging you.

My project includes 7 “entrypoint” scripts, i.e. scripts in bin. In most ways each one is a discrete program; they’re only in the same project because they share many dependencies and much context and are structurally similar.

Anyway, 6 of them are working fine, but one is not; it’s having trouble locating a gem:

$ java -jar continuous-data-0.0.0.jar bin/processors/image_uploader.rb
LoadError: no such file to load -- paseserver
  require at org/jruby/RubyKernel.java:937
  require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:121
    <top> at uri:classloader:/lib/processors/image_upload.rb:3
  require at org/jruby/RubyKernel.java:937
  require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54
    <top> at bin/processors/image_uploader.rb:16

The gem — paseserver is the only one of our gems that’s being referenced from a private git repository rather than rubygems.org. I doubt that’s a coincidence.

The relevant line in Gemfile:

gem 'paseserver', '~>1.3', git: '[email protected]:parkassist/pase-server-ruby-gem.git'

The corresponding section in Gemfile.lock:

GIT
  remote: [email protected]:parkassist/pase-server-ruby-gem.git
  revision: 1aa1785ed35b6979d86506cf633271b27521a8cd
  specs:
    paseserver (1.3.8)
      activemodel
      activesupport
      hashie
      httparty
      json

And when I run rmvn clean package I can definitely see that the gem is being downloaded, installed, copied, etc:

[INFO] --- gem-maven-plugin:1.1.4:exec (bundle install) @ continuous-data ---
[INFO] Fetching gem metadata from https://rubygems.org/
[INFO] Fetching version metadata from https://rubygems.org/
[INFO] Fetching [email protected]:parkassist/pase-server-ruby-gem.git

...

[INFO] Installing activerecord 4.2.5.2
[INFO] Using paseserver 1.3.8 from [email protected]:parkassist/pase-server-ruby-gem.git (at master@1aa1785)
[INFO] Installing maven-tools 1.1.4

...

[INFO] Bundle complete! 15 Gemfile dependencies, 64 gems now installed.
[INFO] Use `bundle show [gemname]` to see where a bundled gem is installed.

and then there’s many, many lines that look like [INFO] Copying file gems/{path} but the files of the paseserver gem never show up.

And finally when I explode the JAR artifact I can’t find the gem in the dir gems or anywhere else:

$ cd pkg/extracted/
~/.../pkg/extracted $ find . -name *pase*
~/.../pkg/extracted $ find . -name *active*
./gems/actionview-4.2.5.2/lib/action_view/helpers/active_model_helper.rb
./gems/activemodel-4.2.5.2
{etc}

😕

Any idea what’s happening here? I’m so close, I’d love to wrap this up! Thank you!

(If I should just open up an issue somewhere I’d be happy to do so; it’s just unclear to me which repo would be appropriate.)

@aviflax
Copy link

aviflax commented Jun 8, 2016

Opened https://github.com/takari/ruby-maven/issues/4 — I hope that’s the right place!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment