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

Unable to load Sybase driver in rc1, works in pre2 #3110

Closed
DougEverly opened this issue Jul 6, 2015 · 12 comments
Closed

Unable to load Sybase driver in rc1, works in pre2 #3110

DougEverly opened this issue Jul 6, 2015 · 12 comments

Comments

@DougEverly
Copy link

Here is a discrepancy between pre2 and rc1.

Working pre2

$ rvm use jruby-9.0.0.0.pre2
Using /usr/local/rvm/gems/jruby-9.0.0.0.pre2

$ jruby -S ./bin/sybase_bug.rb
# ... connects and dumps rows from db

Broken rc1

$ rvm use jruby-9.0.0.0.rc1
Using /usr/local/rvm/gems/jruby-9.0.0.0.rc1

$ jruby -S ./bin/sybase_bug.rb
java/sql/DriverManager.java:596:in `getConnection': java.sql.SQLException: No suitable driver found for jdbc:sybase:Tds:chrcnc-netcool-aos-01.oss.twc.net:4100/alerts
    from java/sql/DriverManager.java:215:in `getConnection'
    from java/lang/reflect/Method.java:606:in `invoke'
    from ./bin/sybase_bug.rb:12:in `<top>’

The files

$ ls
jconn3.jar  sybase_bug.rb

The Code

require 'jconn3.jar’
require ‘pp’

# load the driver
Java::com.sybase.jdbc3.jdbc.SybDriver



uri = "jdbc:sybase:Tds:foo.com:4100/dbname"
sybase = java.sql.DriverManager.get_connection(uri, "user", "pass")
sql = "SELECT TOP 10 * FROM dbname.status"

dbh = sybase.create_statement

res = dbh.execute_query(sql)


while res.next do
  h = Hash.new
  h[:id] = res.getObject("identifier")
  h[:sev] = res.getObject("severity")
  pp h
end
@headius
Copy link
Member

headius commented Jul 6, 2015

Are you able to try jruby head?

@DougEverly
Copy link
Author

Unable to install jruby-head with rvm on mac or linux to try it. Same errors on both platforms. Is there another way to get it?

rvm install jruby-head

git checkout master
Copying from repo to src path...
jruby-head - #mvn...........
Error running 'mvn',
showing last 15 lines of /Users/deverly/.rvm/log/1436213436_jruby-head/mvn.log
[INFO] JRuby Lib Setup ................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.626s
[INFO] Finished at: Mon Jul 06 16:10:41 EDT 2015
[INFO] Final Memory: 8M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.0:enforce (default) on project jruby-parent: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@headius
Copy link
Member

headius commented Jul 6, 2015

Ahh I'm guessing you don't have maven 3.3.1+ installed locally, which we need for our build. Perhaps you could try cloning and building yourself? Just clone repo and run ./mvnw from it.

@DougEverly
Copy link
Author

I’m hitting a wall with building jruby. Mac OS X 10.10.4.

🍺  /Users/deverly/.homebrew/Cellar/maven/3.3.3: 92 files, 9.3M, built in 84 seconds
jruby deverly$ ./mvnw
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/wrapper/MavenWrapperMain : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

@headius
Copy link
Member

headius commented Jul 6, 2015

Looks like you're not building on Java 7+? Make sure Java 7+ is in PATH.

@headius
Copy link
Member

headius commented Jul 6, 2015

Another option: create a temporary git repo that contains all the relevant files to repro and I can take it from there :-)

@mkristian
Copy link
Member

it looks very much that java.lang.Thread.currentThread.setContextClassLoader( JRuby.runtime.jruby_classloader ) or on head JRuby.set_context_class_loader can solve the problem

@DougEverly
Copy link
Author

Here is the the demo repo:
https://github.com/DougEverly/jruby9k_db_test

@headius
Copy link
Member

headius commented Jul 7, 2015

@mkristian @DougEverly Adding set_context_class_loader does indeed make the script boot up properly (though of course I don't have a sybase database here to confirm it works).

Here's my diff to the reproduction script (thanks @DougEverly):

--- sybase_bug_orig.rb  2015-07-07 14:53:42.000000000 -0500
+++ sybase_bug.rb   2015-07-07 14:51:49.000000000 -0500
@@ -3,6 +3,8 @@
 require 'jconn3.jar'
 require 'pp'

+JRuby.set_context_class_loader
+
 # load the driver
 Java::com.sybase.jdbc3.jdbc.SybDriver

@mkristian These sorts of issues worry me. There are a number of Java libraries, JDBC one of the biggest, that really do what context classloader set. If we're not setting it for command line runs anymore, aren't we going to keep getting these bugs?

@headius headius added this to the JRuby 9.0.0.0 milestone Jul 7, 2015
@mkristian
Copy link
Member

@headius setting it for the commandline is just a partial fix. suppose you put THIS code into a gem including the sybDriver then this gem works ONLY on the command line and fails with the same error when using it inside a j2ee or osgi container. but adding JRuby.set_context_class_loader will fix it for all those containers. just recently there was someone on irc using clojure and his code worked via the commandline (1.7.20) but on the servlet it blew up with some strange class loading error. nobody on irc had an clue, including myself. just the moment I wanted to drop out I remembered this context classloader thing and it helped.

@DougEverly
Copy link
Author

@headius I applied your diff and I get this error in rc1 and pre2 (I don’t have head). From your testing tho, it seems that set_context_class_loader will work in head onward.

$ rvm use jruby-9.0.0.0.rc1
Using /usr/local/rvm/gems/jruby-9.0.0.0.rc1
$ jruby -v
jruby 9.0.0.0.rc1 (2.2.2) 2015-06-10 a0bf3b3 OpenJDK 64-Bit Server VM 24.79-b02 on 1.7.0_79-mockbuild_2015_05_14_07_23-b00 [linux-amd64]
$ jruby -S ./bin/sybase_bug.rb
NoMethodError: undefined method `set_context_class_loader' for JRuby:Module
  <top> at ./bin/sybase_bug.rb:6

I am not familiar with the intricacies of set_context_class_loader, but documenting set_context_class_loader, if required, at https://github.com/jruby/jruby/wiki/JDBC would be helpful. (I’d be happy to help out there).

@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015
@mkristian
Copy link
Member

fixed via 7d3bc47

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

No branches or pull requests

4 participants