Using netbeans, a required jar is referenced from the java configuration
and all works well.
Creating a gem containing the jar, how is the jar found when using the
gem.
I have tried "require", "include_package", "include_class" but none seem
to work for me.
How should this be set up?
Thanks
Paul F Fraser
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
on 2009-05-14 23:50
on 2009-05-15 01:57
On Thu, May 14, 2009 at 4:49 PM, Paul Fraser <paulf@a2zliving.com> wrote: > Using netbeans, a required jar is referenced from the java configuration and > all works well. > Creating a gem containing the jar, how is the jar found when using the gem. > I have tried "require", "include_package", "include_class" but none seem to > work for me. > How should this be set up? The jar must be on the $LOAD_PATH. Usually when a gem gets loaded, directories like $YOUR_GEM/lib will be added to the load path. So if you place your jar file in $YOUR_GEM/lib/your_gem_ext.jar, you can simply load the jar file by doing 'require "your_gem_ext"'. Hope that answers the question, /Nick --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-15 15:27
Nick Sieger wrote: > The jar must be on the $LOAD_PATH. Usually when a gem gets loaded, > directories like $YOUR_GEM/lib will be added to the load path. So if > you place your jar file in $YOUR_GEM/lib/your_gem_ext.jar, you can > simply load the jar file by doing 'require "your_gem_ext"'. > > Hope that answers the question, > /Nick Hi Nick, Checking the project before creating the gem.. I am using "Netbeans Dev 200905120201" (1) require 'h2-1.1.106' (the h2 database jar) does NOT work with h2-1.1.106.jar in the project/lib dir but works with (2) C:\Users\paul\dev\netbeans_projects\db_all\lib\h2-1.1.106.jar added in netbeans Project Properties > Java > JRuby Classpath (tab) the c:\Users\paul\dev\netbeans_projects\db_all\lib is being added to the LOAD_PATH ok. I think (1) is how you suggest it should work. Any ideas.. Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-15 15:57
We found we needed to do something like this: require 'sinatra.jar' gem :sinatra before using it in our application. --- Colin Jones On May 15, 2009, at 8:26 AM, Paul Fraser <paulf@a2zliving.com> wrote: >>> none seem to >> /Nick > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-15 16:34
Colin, Thanks for your input. Unfortunately -- After changing the jar name to h2 (gem :h2-1.1.106 won't work) and trying require 'h2.jar' gem : h2 still same problem. Paul Colin Jones wrote: > On May 15, 2009, at 8:26 AM, Paul Fraser <paulf@a2zliving.com> wrote: >>>> I have tried "require", "include_package", "include_class" but none >>> Hope that answers the question, >> >> the c:\Users\paul\dev\netbeans_projects\db_all\lib is being added >> to the LOAD_PATH ok. >> >> I think (1) is how you suggest it should work. Any ideas.. >> >> Paul >> --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-15 16:51
On Fri, May 15, 2009 at 8:26 AM, Paul Fraser <paulf@a2zliving.com> wrote: >>> I have tried "require", "include_package", "include_class" but none seem >> Hope that answers the question, > in netbeans Project Properties > Java > JRuby Classpath (tab) > > the c:\Users\paul\dev\netbeans_projects\db_all\lib is being added to the > LOAD_PATH ok. > > I think (1) is how you suggest it should work. Any ideas.. So "db_all" is the name of the project? The "lib" directory doesn't normally get added automatically. You'll probably need to add it in an entry point script or a Rakefile. Typically you can do this by relative-pathing from File.dirname(__FILE__). So say if the script you're running is in db_all/main.rb, putting $LOAD_PATH << File.join(File.dirname(__FILE__), "lib") near the start of the script should allow you to later require 'h2-1.1.1.106' /Nick --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-17 06:10
On Fri, May 15, 2009 at 8:26 AM, Paul Fraser <paulf@a2zliving.com> wrote: >>>> I have tried "require", "include_package", "include_class" but none seem >>> Hope that answers the question, >> in netbeans Project Properties > Java > JRuby Classpath (tab) > relative-pathing from File.dirname(__FILE__). So say if the script > you're running is in db_all/main.rb, putting > > $LOAD_PATH << File.join(File.dirname(__FILE__), "lib") > > near the start of the script should allow you to later > > require 'h2-1.1.1.106' > > /Nick > Nick, After some research it seems my problem might relate to http://jira.codehaus.org/browse/JRUBY-2495 The jar is installed in the project lib directory. This code works when the jar is on the classpath (set in netbeans) and fails when the require method is used. When the jar is not on the classpath and require 'h2-1.1.106' is used, the error relates to a driver not being found. Also fails with the Vladimar suggestion re the ContextClassLoader Thread Could this still a problem related to http://jira.codehaus.org/browse/JRUBY-2495 ? require 'rubygems' require 'java' #require 'jruby' #java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader) require 'sequel' #require 'h2-1.1.106' $LOAD_PATH.unshift File.dirname(__FILE__) connection_str = "jdbc:h2:db1;USER=sa" begin db = Sequel.connect(connection_str) db.test_connection puts "Open Database OK" rescue puts "Open Database Failed = #{connection_str}" nil end Thanks Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-17 19:58
On Sat, May 16, 2009 at 11:08 PM, Paul Fraser <paulf@a2zliving.com> wrote: > Could this still a problem related to > $LOAD_PATH.unshift File.dirname(__FILE__) > > connection_str = "jdbc:h2:db1;USER=sa" > begin > db = Sequel.connect(connection_str) > db.test_connection > puts "Open Database OK" > rescue > puts "Open Database Failed = #{connection_str}" > nil > end We have to jump through some hoops with AR-JDBC in order to use jar files require'd by JRuby -- perhaps you're running into this issue. The issue is the following: http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DriverManager.html "When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application." The problem is that any drivers require'd by JRuby end up in a child classloader of the one that started JRuby, so DriverManager doesn't see them. The workaround (which may require patching Sequel) is to do something like the following [1]: def connection(url, user, pass) Jdbc::DriverManager.getConnection(url, user, pass) rescue # bypass DriverManager to get around problem with dynamically loaded jdbc drivers props = java.util.Properties.new props.setProperty("user", user) props.setProperty("password", pass) create.connect(url, props) end def create driver_class.new end /Nick [1]: http://github.com/nicksieger/activerecord-jdbc-adapter/blob/e0a354d77f7005c118c958727634ad8736acd742/lib/active_record/connection_adapters/jdbc_adapter.rb#L256-268 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2009-05-18 04:33
Nick Sieger wrote: >> error relates to a driver not being found. >> #require 'h2-1.1.106' >> nil > attempt to locate a suitable driver from amongst those loaded at > rescue > end > > /Nick > > [1]: http://github.com/nicksieger/activerecord-jdbc-adapter/blob/e0a354d77f7005c118c958727634ad8736acd742/lib/active_record/connection_adapters/jdbc_adapter.rb#L256-268 > > Nick, The plot thickens.. When attempting to try your suggestion, I discovered that the driver is found when debugging the code and not found during normal run if the jdbc-h2 gem is installed. This is with no reference to your suggested code at all. Sequel (internally) requires 'h2' if the gem is installed. It seems that the debugger (in netbeans) does clever things with the driver when accessing the jdbc-h2 gem. The debugger might be putting the jar on the classpath. I will try and check if this is happening. Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2012-01-12 20:26
Hi Nick, I'm actually having the same problem using dbd-jdbc and jdbc-jtds. In my setup I am using bundler in standalone mode to add the necessary gems to my load path and launching my application. When I use jruby.exe to launch the application the driver is found, but when I do 'java -classpath jruby-complete.jar org.jruby.Main a.rb it doesn't find the driver. I'm inclined to agree with you that it is a classloader issue. Seeing that you are one of the owners of dbd-jdbc, doesn't it make sense to put some magic in there seeing that its probably a common problem for jdbc? -- View this message in context: http://ruby.11.n6.nabble.com/Jars-in-Gems-tp3465223p3665943.html Sent from the JRuby - User mailing list archive at Nabble.com.
on 2012-01-12 21:32
Came across http://jira.codehaus.org/browse/JRUBY-2495 #JRUBY-2495 If it made it into jruby then I don't see why the jtds driver can't be found by DriverManager or am I missing something? -- View this message in context: http://ruby.11.n6.nabble.com/Jars-in-Gems-tp3465223p3666051.html Sent from the JRuby - User mailing list archive at Nabble.com.
on 2012-01-12 21:42
Found that adding -Xbootclasspath/a:..\lib\jruby-complete.jar;.\bundle solved it in my environment. Not sure what side-effects it has though. -- View this message in context: http://ruby.11.n6.nabble.com/Jars-in-Gems-tp3465223p3666077.html Sent from the JRuby - User mailing list archive at Nabble.com.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.