Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically import jars from "~/.m2" #4464

Closed
abhi18av opened this issue Jan 30, 2017 · 6 comments
Closed

Automatically import jars from "~/.m2" #4464

abhi18av opened this issue Jan 30, 2017 · 6 comments
Milestone

Comments

@abhi18av
Copy link

Hi @jruby team :)

Hey, I find myself relying more and more on jRuby - especially with using the native java libraries. I was wondering if there's a way I can customize pry or jirb to automatically import the ~/.m2 jars.

  • jruby -v
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 OpenJDK 64-Bit Server VM 25.112-b16 on 1.8.0_112-b16 +jit [linux-x86_64]
  • uname -a
Linux eklavya 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I have most of my useful libs downloaded by leiningen into the ./m2.

Please excuse me, if this might be a silly question but I'd love to explore as many java libs with jRuby as I can.

@kares
Copy link
Member

kares commented Jan 30, 2017

~/.irbrc will do - so you just kind of Dir.glob('~/.m2/*.jar').each { |jar| load jar }

@kares kares added this to the Non-Release milestone Jan 30, 2017
@abhi18av
Copy link
Author

@kares , I made a ~/.irbrc and placed the command in but it doesn't seem to work with jirb.

Say for example, I wish to import require '~/commons-math3-3.6.1' automatically everytime I run jruby -S pry`.

Shouldn't one prefer pry since it offers code-completion?

@kares
Copy link
Member

kares commented Jan 30, 2017

@abhi18av if the require did not fail than it must have done something

you could also do $CLASSPATH << File.expand_path('~/commons-math3-3.6.1/commons-math.jar') instead
make sure the .jar exists (maybe validate the dir/jar pieeces you add to $CLASSPATH)

jirb is just irb (you can do a puts line to verify it loaded fine). regarding pry there's a .pryrc.

the tracker is more-less for issues or for q that might be bugs.
would ask around on SO/IRC or the mailing-list if you have questions like whether "pry is better since it offers code-completion" :)

@kares kares closed this as completed Jan 30, 2017
@abhi18av
Copy link
Author

Sure @kares , I understand :)
Thank you for your time 👍

@enebo
Copy link
Member

enebo commented Jan 30, 2017

@abhi18av @kares I would not suggest the blanket require kares mentioned (since on my system you would likely run out of memory including that many jars) but the glob itself did not work because it did not contain '**': p Dir.glob(%q{/Users/enebo/.m2/**.jar}) . I would consider making some small method with artifact name and artifact version which globbed out what you want to require since over time you will also end up with n copies of the same library in .m2/repository (it is the maven way).

@mkristian
Copy link
Member

I need to give my 2 cents as well: Jars.require_jar 'de.regnis.q.sequence', 'sequence-library', '1.0.2' will require the jar from default local maven repository, i.e. from ~/.m2/
but that might be not so helpful as you need to resolve all your jars manually. but you will not load the same artifact with different versions in your classloader which will most likely happen with the glob approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants