On a machine I have only a user account on, I want to dump the output of a job into an sqlite database instead of textfiles. To this end, I run jruby from the jarfile.
The approach usings gems (dbi, dbd/Jdbc, jdbc/sqlite3) from a local GEM_HOME did not work (No suitable driver found) and also produces deprecation messages from the gems ("include_class is deprecated. Use java_import.")
I turned to Zentus' sqlitejdbc-v056.jar and ran JRuby with Zentus' in the path:
java -cp .:sqlitejdbc-v056.jar -jar jruby-complete-1.7.0.preview1.jar test.rb
where test.rb in inspired by http://www.zentus.com/sqlitejdbc/ and How to initialize the SQLite3 JDBC driver in JRuby? :
require 'java'
require '/home/jens/jruby/sqlitejdbc-v056.jar'
org.sqlite.JDBC # load the driver so DriverManager detects it
p clazz = Java::JavaClass.for_name("org.sqlite.JDBC")
java.sql.DriverManager.registerDriver( clazz )
#Java::OrgSqlite::JDBC # alternate means of same
puts "enumerating..."
java.sql.DriverManager.getDrivers.each{ |e| puts e }
connection = java.sql.DriverManager.getConnection 'jdbc:sqlite:/home/jens/jruby/test.db'
begin
statement = connection.createStatement
...
ensure
connection.close
end
The output I get from this is:
class org.sqlite.JDBC
enumerating...
sun.jdbc.odbc.JdbcOdbcDriver#73415727
DriverManager.java:602:in `getConnection': java.sql.SQLException: No suitable driver found for jdbc:sqlite:/home/jens/jruby/test.db
from DriverManager.java:207:in `getConnection'
from NativeMethodAccessorImpl.java:-2:in `invoke0'
...
Curiously, the driver is listed by the DriverManager, but not deemed suitable for sqlite.
I'm looking forward to any suggestions.
First of all you should use bundler to manage your gem dependencies. Bundler uses a Gemfile to list the gems you need (place it where your script is). And make sure that jruby is in your path.
In your case the Gemfile should contain:
source 'http://rubygems.org'
gem "activerecord-jdbcsqlite3-adapter", ">= 1.2"
Then execute:
bundle install --path vendor/bundle
Then modify your script like this:
require 'rubygems'
require "java"
require 'bundler/setup'
require 'jdbc/sqlite3'
Bundler.require
org.sqlite.JDBC # load the driver so DriverManager detects it
p clazz = Java::JavaClass.for_name("org.sqlite.JDBC")
java.sql.DriverManager.registerDriver( clazz )
puts "enumerating..."
java.sql.DriverManager.getDrivers.each{ |e| puts e }
connection = java.sql.DriverManager.getConnection 'jdbc:sqlite:/home/jens/jruby/test.db'
begin
statement = connection.createStatement
ensure
connection.close
end
Related
I am running a Debian 10 (Buster) Server for my Rails 6.0.3, Ruby 2.6.3, Mina 1.2.3 app. When I run Mina deploy it errors out but does not give me enough to help me understand what I need to do to resolve the issue.
Mina Deploy output
Precompiling asset files
$ RAILS_ENV="production" bundle exec rake assets:precompile
Traceback (most recent call last):
3: from /var/www/site/tmp/build-15965768145748/vendor/bundle/ruby/2.6.0/bin/ruby_executable_hooks:24:in `<main>'
2: from /var/www/site/tmp/build-15965768145748/vendor/bundle/ruby/2.6.0/bin/ruby_executable_hooks:24:in `eval'
1: from /usr/local/rvm/gems/ruby-2.6.3/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.6.3/bin/rake:23:in `load': cannot load such file -- /usr/local/rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/specifications/default/exe/rake (LoadError)
! ERROR: Deploy failed.
Deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'
set :application_name, 'site'
set :domain, 'server'
set :user, 'deployer'
set :deploy_to, "/var/www/site"
set :repository, "git#github.com:git.git"
set :branch, 'master'
set :rvm_use_path, '/etc/profile.d/rvm.sh'
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')
task :remote_environment do
ruby_version = File.read('.ruby-version').strip
raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?
invoke :'rvm:use', 'ruby-2.6.3'
end
desc "Deploys the current version to the server."
task :deploy do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
on :launch do
end
end
end
namespace :passenger do
desc "Restart Passenger"
task :restart do
queue %{
echo "-----> Restarting passenger"
cd #{deploy_to}/current
#{echo_cmd %[mkdir -p tmp]}
#{echo_cmd %[touch tmp/restart.txt]}
}
end
end
I have made sure that yarn is installed and working on my Production machine. When I run the precompile on the Production machine, it runs through successfully. But still errors out in the Mina Deploy with no change in the error text. I have looked into this article In doing so I have commented out the suggested code snippet just to test, but that did not change anything. In looking at my bashrc, I do not see any snippets with EXPORT or SOURCE at the beginning of them.
EDIT: When I run the precompile on the server side, each new deployment folder seems like it will give me this issue.
I am trying to configure my Sencha Touch 2 application build process such that linked fonts have correct path in the CSS.
I have added fonts_path to MyApp/resources/sass/config.rb:
# Get the directory that this configuration file exists in
dir = File.dirname(__FILE__)
# Load the sencha-touch framework automatically.
load File.join(dir, '..', '..', 'touch', 'resources', 'themes')
# Compass configurations
sass_path = dir
css_path = File.join(dir, "..", "css")
fonts_path = File.join(dir, "..", "fonts")
# Require any additional compass plugins here.
images_dir = File.join(dir, "..", "images")
output_style = :compressed
environment = :production
which should change the fonts path used in the SCSS:
#include icon-font('Pictos', font-files('pictos-web.svg', 'pictos-web.eot'));
but this still compiles to
#font-face{font-family:"Pictos";src:url('/stylesheets/fonts/pictos-web.svg') format('svg'),url('/stylesheets/fonts/pictos-web.eot') format('embedded-opentype')}
So the fonts path used in is the CSS still is /stylesheets/fonts/, and I don't know why.
I have tried to find the config.rb used by calling sencha -d app build production, but this does not give me any more details as to the config file used:
[INF] -compass-compile-sass-dir:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x64-mingw32]
[DBG] exit code was : 0
[DBG] exit code was : 0
[DBG] ruby detected, checking for version in : ruby 2.2.3p173 (2015-08-18 revision 51636) [x64-mingw32]
[DBG] setting GEM_HOME to C:\Users\urban\bin\Sencha\Cmd\6.0.1.76\extensions\sencha-compass\gems
[INF] executing compass using system installed ruby runtime
[DBG] executing compass : ruby C:\Users\urban\bin\Sencha\Cmd\6.0.1.76\extensions\sencha-compass\gems\bin\compass compile --force --trace
identical ../css/app.css
[DBG] exit code was : 0
Now I am not sure that I edited the correct config.rb, there are quite some:
MyApp/resources/sass/config.rb
MyApp/touch/packages/sencha-touch-grid/examples/grid/resources/sass/config.rb
MyApp/touch/packages/sencha-touch-grid/examples/summarygrid/resources/sass/config.rb
MyApp/.backup/MyApp/2.3.1.410/resources/sass/config.rb
MyApp/touch/resources/sass/config-debug.rb
MyApp/touch/resources/sass/config.rb
MyApp/touch/resources/themes/vendor/config/compass-recipes/config.rb
Which one is it or is it neither?
I am trying to use phantomjs as installed via npm to perform my unit tests for ScalaJS.
When I run the tests I am getting the following error:
/usr/bin/env: node: No such file or directory
I believe that is because of how phatomjs when installed with npm loads node:
Here is the first line from phantomjs:
#!/usr/bin/env node
If I change that first line to hardcode to the node executable (this involves modifying a file installed by npm so it's only a temporary solution at best):
#!/home/bjackman/cgta/opt/node/default/bin/node
Everything works.
I am using phantom.js btw because moment.js doesn't work in the NodeJSEnv.
Work Around:
After looking through the plugin source is here the workaround:
I am forwarding the environment from sbt to the PhantomJSEnv:
import scala.scalajs.sbtplugin.ScalaJSPlugin._
import scala.scalajs.sbtplugin.env.nodejs.NodeJSEnv
import scala.scalajs.sbtplugin.env.phantomjs.PhantomJSEnv
import scala.collection.JavaConverters._
val env = System.getenv().asScala.toList.map{case (k,v)=>s"$k=$v"}
olibCross.sjs.settings(
ScalaJSKeys.requiresDOM := true,
libraryDependencies += "org.webjars" % "momentjs" % "2.7.0",
ScalaJSKeys.jsDependencies += "org.webjars" % "momentjs" % "2.7.0" / "moment.js",
ScalaJSKeys.postLinkJSEnv := {
if (ScalaJSKeys.requiresDOM.value) new PhantomJSEnv(None, env)
else new NodeJSEnv
}
)
With this I am able to use moment.js in my unit tests.
UPDATE: The relevant bug in Scala.js (#865) has been fixed. This should work without a workaround.
This is indeed a bug in Scala.js (issue #865). For future reference; if you would like to modify the environment of a jsEnv, you have two options (this applies to Node.js and PhantomJS equally):
Pass in additional environment variables as argument (just like in #KingCub's example):
new PhantomJSEnv(None, env)
// env: Map[String, String]
Passed-in values will take precedence over default values.
Override getVMEnv:
protected def getVMEnv(args: RunJSArgs): Map[String, String] =
sys.env ++ additionalEnv // this is the default
This will allow you to:
Read/Modify the environment provided by super.getVMEnv
Make your environment depend on the arguments to the runJS method.
The same applies for arguments that are passed to the executable.
So.. I have this problem (the one in the title). Just to give a background about what I did:
Create a Java class called Carro:
public class Carro{
public Carro(){}
public void turnon(String sound){
System.out.println(sound);
}
}
I've compile it:
javac Carro.java
And created a .jar:
jar -cf Carro.jar Carro.class
So, I created a new lein project:
lein new test
Created a /lib directory and pasted the Carro.jar in it.
Create a folder called carro in test/src/ directory and create a .clj file, called car.clj:
(ns carro.car
(:import [Carro] )
)
(defn callCarro []
(let [car (new Carro)]
(.turnon "vruuum!" car)
)
)
After all of that, I edited the project.clj file and add a :import [Carro] after the last parenthesis.
So, when I run the project using lein repl, I get this error:
$ lein repl
user=> (require 'carr.car :reload)
CompilerException java.lang.IllegalArgumentException:
Unable to resolve classname: Carro, compiling:(carro/car.clj:6)
Any ideas to solve this... Problem?
Leiningen 2 relies on maven to manage dependencies. Version 1 used to copy jars to the lib directory but this behavior was removed (see https://github.com/technomancy/leiningen/blob/stable/doc/FAQ.md). If you need a certain jar for your project, the easiest way is to install that jar on your local maven repo and let leiningen do the rest.
Maven (and so leiningen) needs a version, a group and an artifact for the jar you are working with (see https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#artifact-ids-groups-and-versions). So our first step will be to rename Carro.jar to Carro-0.1.0.jar. To make things a little easier, lets use a leiningen plugin to do the rest. Add the lein-localrepo plugin to your project.clj, something like:
(defproject foo "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]]
:plugins [[lein-localrepo "0.4.1"]])
Then you can ask leiningen for the coordinates of the Carro dependency:
$ lein localrepo coords Carro-0.1.0.jar
Carro-0.1.0.jar Carro/Carro 0.1.0
That last part is the info needed to install to the mvn repo:
$ lein localrepo install Carro-0.1.0.jar Carro/Carro 0.1.0
After that,the jar is installed in your mvn repository: ~/.m2/repository/Carro/Carro/0.1.0/Carro-0.1.0.jar. So finally, add the newly installed dependency to project.clj:
(defproject foo "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[Carro/Carro "0.1.0"]]
:plugins [[lein-localrepo "0.4.1"]])
And then from the repl:
$ lein repl
user=> (new Carro)
#<Carro Carro#7c04703c>
I suspect there may be multiple causes:
Clojure has trouble loading classes without a package which causes this.
that is not the typical location for test classes if you are using Leiningen
If you didn't run (import 'Classname) from the repl you will need to do that as well.
I am having some fun with Jruby, but I am having troubles getting my app deployed on EngineYard. Under deploy I am getting the follow error:
ActiveRecord::JDBCError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(2147483647) DEFAULT NULL' at line 1: ALTER TABLE `iterations` CHANGE `points` `points` longtext(2147483647) DEFAULT NULL
Even though my database.yml uses SQLITE and not MySQL. The migration file is listed as:
class ChangePointsToLongtext < ActiveRecord::Migration
def up
change_column :iterations, :points, :longtext
end
def down
change_column :iterations, :points, :text
end
end
I am almost certrain its the change_column - I have tried t.change and looked around for other syntax changes. I think it may be an issue with the Jruby version running on EngineYard - which I can't update.
My GemFile looks like this:
platforms :jruby do
gem 'jruby-openssl'
gem 'trinidad'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
gem 'jdbc-mysql', :require => false
gem 'jdbc-sqlite3', :require => false
end
So I believe I have all the relevant gems loaded in order to establish a database under Jruby, although I may be very wrong! I think I just need an alternative to change_column
Has anyone run into a similar problem? Or have any advice on changes? any help is always much appreciated!
Thanks
C
First, please use https://support.cloud.engineyard.com/ if you need help with Engine Yard.
Second, EY does not support SQLite. When your application is deployed to EY, EY will replace database.yml with appropriate information so that your application can use DB indicated in the environment configuration. The DB choice should default to MySQL when you set up your environment.
And finally, it appears that something is generating the incorrect SQL statement. Seeing that a similar migration works with MRI and mysql2 adapter, the issue probably lies with JDBC adapter. You can open an issue at https://github.com/jruby/activerecord-jdbc-adapter/issues or http://bugs.jruby.org.
Thanks.