Is there any Gem available to generate UUID in Jruby using java.util.UUID?
I don't know of a gem, but this is trivial code in JRuby:
$ jirb
irb(main):001:0> uuid = java.util.UUID.randomUUID
=> #<Java::JavaUtil::UUID:0x37a6af53>
irb(main):002:0> puts uuid
944b0019-d122-4f2b-9e85-23836e0f3d72
Related
Not able to start rails5 with jruby, getting the following error.
gavinyap#gavin-ubuntu ~/Development/rails5app rails s
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from require at bin/rails:4)
Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-jdbcmysql-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
Backtrace for gem load error is:
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:13:in `<module:TypeCast>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:7:in `<module:Jdbc>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:4:in `< module:ConnectionAdapters>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/type_cast.rb:3:in `<top>'
/home/gavinyap/.rvm/gems/jruby-9.1.2.0/gems/activerecord-jdbc-adapter-1.3.20/lib/arjdbc/jdbc/column.rb:1:in `singleton cla
Versions of Jruby and Rails
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f
OpenJDK 64-Bit Server
VM 25.91-b14 on 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14 +jit [linux-x86_64]
Rails 5.0.0
The ActiveRecord JDBC gem has not been updated for Rails 5. Checking the project in GitHub shows some development activity early this year but there is no indication when a new gem will be released for Rails 5.
add gem 'activerecord-jdbcmysql-adapter', '~> 5.0.pre1' to your gemfile
I've create a wrapper gem for connecting to a tibco queue & uploaded that gem to my local gemserver. When I try to include the wrapper gem in other projects, I get the following error:
Bundler could not find compatible versions for gem "jruby-jms":
In Gemfile:
jruby-jms (>= 1.2.0, ~> 1.2) java
tibco_client (>= 0) java depends on
jruby-jms (>= 1.2.0, ~> 1.2) ruby
jruby-jms (>= 0) java
jruby-jms (>= 0) ruby
Could not find gem 'jruby-jms (>= 1.2.0, ~> 1.2) ruby in any of the sources
I am trying to figure out how to list the runtime dependency but I can't find any instruction or examples:
spec.platform = 'java'
spec.add_runtime_dependency 'jruby-jms', '~> 1.2', '>= 1.2.0'
Does anybody have experience in resolving something like this? I'm using jruby-1.7.19 (also tried 1.7.4, same result).
I found the problem was in my Gemfile. Syntax found on stackoverflow.
gem 'tibco_client', :source => 'http://gemserver:9292', :platforms => 'jruby'
I'm using JRuby 1.7.2, along with DataMapper, and I'm getting an error I can't find an answer to.
I'm just testing out DataMapper along with MySQL 5.5 to see if it will run fine when I build around it. Here's the file I'm testing:
require "data_mapper"
require "keys"
DataMapper.setup(:default, "mysql://#{$user}:#{$pass}#localhost/test_db")
And when I run this, I get the error:
NameError: cannot load Java class com.mysql.jdbc.Driver
And it points to the DataMapper.setup line.
My Gemfile should be alright:
source :rubygems
gem "sinatra"
gem "trinidad"
gem "data_mapper"
# do a `sudo apt-get install libmysqlclient-dev` first
gem "dm-mysql-adapter"
gem "jdbc-mysql"
Is there anything I'm missing? I have MySQL set up with a user/pass locally already.
This is a common error when running JDBC clients for MySQL. You need to make sure you have mysql-connector-java-bin.jar on the classpath. You can download it from here.
I'm using Rails 3.2.9 and to solve the problem I added this to my application.rb
if defined? JRUBY_VERSION
require 'jdbc/mysql'
Jdbc::MySQL.load_driver
end
actually, the correct answer is to work-around an incompatibility between 5.1.13 and 5.1.22 !
jdbc-mysql gem already contains the mysql-connector.jar it just ain't auto-loading anymore :
https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-mysql (read the README)
you can also force the driver to auto-load using a Java system property e.g. from a cmd line :
jruby -J-Darjdbc.mysql.autoload=true -S rake ...
I had the same error when trying to use a mysql database from jruby/rails4. In my case this line was missing from ./Gemfile:
gem 'jdbc-mysql'
I am working on Rails 2.3.8. I have following in my environment.rb
config.gem "redis"
config.gem "redis-namespace", :lib => "redis/namespace"
When I list my redis gems then I see:
redis (2.0.3)
redis-namespace(0.7.0)
When I run rake gems:install then I get an error that says:
no such file to load -- redis-namespace
Shouldn't requiring "redis/namespace" solve the issue? Can anyone please help me with this?
It sounds as if rake gems:install depends on the very gem it is trying to install.
Try using rails_gem_install or bundler instead.
I would like to use JRuby to run a script which populates a database. I am already running JRuby/Rails for a Rails server in another application, and this setup works.
I ran the script (foo.rb) fine until I tried to include the ActiveRecord gem in line 2. The code looks like this:
require 'rubygems'
require 'activerecord'
require 'csv'
nf=[]
Dir["./*.*"].each{|f|nf<<f if File::ctime(f) + 600 > Time.now}
nf.each{|f| p f.inspect}
The error I get looks like this:
unix> jruby --1.9 foo.rb
LoadError: no such file to load -- activerecord
require at org/jruby/RubyKernel.java:1047
require at /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
(root) at foo.rb:2
My gem listing includes all of rails 3.0.10, activerecord 3.0.10, activerecord-jdbc-adapter 1.2.0, activerecord-jdbcmysql-adapter 1.2.0.
I also have an environment variable (JRUBY-OPTS=--1.9) which tells JRuby to run version 1.9 when I use Rails.
What am I missing to get JRuby 1.9 to run with ActiveRecord 3.0.10 to hit a MySQL database?
Change your require to:
require 'active_record'