标签: jruby

在Rails上使用嵌入式Derby和JRuby

尝试将JRuby 1.2.0和Rails 2.3.2与嵌入式Derby数据库一起使用.我已经复制derbytools.jarderby.jar$RUBY_HOME/lib,但rake db:migrate仍然给:

The driver encountered an error: 
    cannot load Java class org.apache.derby.jdbc.ClientDriver
Run Code Online (Sandbox Code Playgroud)

Aaaand ......我发挥了预感并想出来了.所以,我会在这里发布,以防其他人遇到同样的问题.

我在网上找到的几乎所有文档都有以下database.ymlDerby配置:

development:
    adapter: jdbc
    driver: org.apache.derby.jdbc.ClientDriver
    url: jdbc:derby:[db];create=true
    username: xxx
    password: xxx
Run Code Online (Sandbox Code Playgroud)

这可能适用于客户端/服务器设置,但对于嵌入式Derby设置,您需要:

development:
    adapter: jdbc
    driver: org.apache.derby.jdbc.EmbeddedDriver
    url: jdbc:derby:[db];create=true
    username: xxx
    password: xxx
Run Code Online (Sandbox Code Playgroud)

请注意'EmbeddedDriver',而不是'ClientDriver'.

ruby-on-rails jruby derby

5
推荐指数
1
解决办法
2346
查看次数

将jruby脚本打包成jar并包含所有依赖项?

有没有办法让我当前的jruby脚本成为独立的单个可执行文件,如jar或exe?

ruby java packaging jruby

5
推荐指数
1
解决办法
615
查看次数

在Tomcat中跟踪JRuby on Rails的PermGen问题

我们正在运行一个在Tomcat上运行的Rails上写的JRuby的小型Web应用程序.我们正在使用与另一个生产Web应用程序共享的Spring后端.不幸的是,我们一直遇到PermGen问题.

操作系统:Ubuntu Linux 2.6.24-24-server#1 SMP x86_64 GNU/Linux Java:1.6.0_21 Tomcat:6.0.28 JRuby:1.5.0 Rails:2.3.7

我们目前正在被谷歌,雅虎和百度抓获,因此网站使用率上升.我一直在使用JConsole监视Tomcat,我们肯定会看到有太多类的问题.当tomcat启动时,我们加载了大约12,000个类.8小时后,我们加载了近75,000个班级.PermGen同时从100MB增加到460MB.

类卸载工作正常,但它只在同一个8小时内卸载了~500个类.PermGen似乎永远不会被收集.

我们正在运行Tomcat的以下VM选项:

-Xms2048m -Xmx2048m -XX:MaxPermSize=512m -XX:PermSize=128m \
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=4 \
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
Run Code Online (Sandbox Code Playgroud)

显然存在某种泄漏.问题是在哪里?关于如何追踪谁以及对此负责的任何建议?我希望这是我们的一些非常愚蠢的错误,但我不知道从哪里开始.

任何建议将不胜感激.

编辑

看起来我们正在看到为每个传入请求创建一个新类.

编辑2

这肯定与JRuby有关.使用JConsole,我为类加载器启用了详细模式.以下是来自catalina.out的示例:

[Loaded anon_class1275113147_895127379 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
[Loaded anon_class1354333392_895127376 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
[Loaded anon_class1402528430_895127373 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
Run Code Online (Sandbox Code Playgroud)

那么问题就变成了如何追踪负责创建这些额外课程的一方?

编辑3

不确定这是否是问题所在,但不知何故,我们最终会遇到疯狂的类加载器.跑jmap -permstat PID了但得到了:

class_loader  classes bytes       parent_loader   alive?              type
total = 1320  135748  947431296   N/A             alive=1, dead=1319  N/A
Run Code Online (Sandbox Code Playgroud)

这看起来有点过分了.大多数有三种类型的类加载器的一个:sun.reflect.DelegatingClassLoader,org.jruby.util.JRubyClassLoaderorg.jruby.util.ClassCache$OneShotClassLoader.再次,样本输出来自jmap -permstat:

class_loader            classes bytes      parent_loader           alive? …
Run Code Online (Sandbox Code Playgroud)

tomcat memory-leaks jruby jrubyonrails permgen

5
推荐指数
1
解决办法
3353
查看次数

为什么不使用Rhino for JVM应用程序?

我想使用简洁,动态的语言为JVM开发一些应用程序.最流行的选择似乎是Jython,JRuby,Groovy,也许还有Clojure.

Rhino似乎很快且非常稳定,但我看不到有关Rhino开发和讨论的书籍.除了嵌入式脚本之外,为什么显然很少使用JavaScript?

编辑:我发现这个问题提供了有关基于Rhino的开发的可行性的信息.

groovy jython jruby rhino jvm-languages

5
推荐指数
1
解决办法
1764
查看次数

如果没有JRuby/gem,是否可以在Java中运行Cucumber?

我是Cucumber,JRuby,Gems的新手以及它是如何工作的.

我喜欢用简单的英语写下测试用例的想法,但我并不热衷于安装很多新工具(我真的非常喜欢Java),只是为了让Cucumber正常运行.

所以我有几个问题.

1)我是否需要安装JRuby/Ruby才能在Java中使用Cucumber?没办法避免这个?

2)如果没有,是否有替代测试工具,类似于Cucumber,开箱即用的Java工作?

为了让Cucumber /类似工具正常工作,我还有哪些方法可以最小化新工具?

ruby java jruby cucumber

5
推荐指数
2
解决办法
3518
查看次数

Ruby相当于C#Linq Aggregate方法

什么是相当于Linq Aggregate方法的红宝石.它的工作原理是这样的

  var factorial = new[] { 1, 2, 3, 4, 5 }.Aggregate((acc, i) => acc * i);
Run Code Online (Sandbox Code Playgroud)

每次将数组序列中的值传递给lambda时,变量acc都会累积.

c# ruby linq aggregate jruby

5
推荐指数
1
解决办法
1871
查看次数

让ANSICON在Windows 7 Enterprise 64位上运行的问题

我一直试图让1.50或1.40 ANSICON(https://github.com/adoxa/ansicon)工作,看了很多关于如何安装这个的页面:http: //blog.mmediasys.com/2010/ 11/24/we-all-love-colors / http://carol-nichols.com/2011/03/the-system-cannot-find-the-path-specified/

等等....

所以,我将我的AutoRun设置为"C:\ usr\bin\ansi140\x64\ansicon.exe"-p,我也测试了150但是没有变化.

我的整个团队都没有这个问题,但是我无法解决这个问题.我仍然在命令提示符下得到乱码垃圾:

  Scenario: Residential caller chooses to hear payment locations closest to home and there are 3 locations available which are in a 25 miles radius.?[90m #
 features\payment_locations.feature:5?[0m
    ?[32mGiven the call flow is '?[32m?[1mDivisional?[0m?[0m?[32m'?[90m
                          # features/step_definitions/common_steps.rb:5?[0m?[0m
    ?[32mAnd the ani is '?[32m?[1m6101234572?[0m?[0m?[32m'?[90m
                          # features/step_definitions/common_steps.rb:9?[0m?[0m
    ?[32mAnd the dnis is '?[32m?[1m9?[0m?[0m?[32m'?[90m
                          # features/step_definitions/common_steps.rb:13?[0m?[0m
    ?[31mWhen the call is started?[90m
    # features/step_definitions/common_steps.rb:17?[0m?[0m
?[31m      Connection refused - Connection refused (Errno::ECONNREFUSED)?[0m
?[31m      org/jruby/ext/socket/RubyTCPSocket.java:121:in `initialize'?[0m
?[31m      org/jruby/RubyIO.java:864:in `new'?[0m …
Run Code Online (Sandbox Code Playgroud)

cmd jruby ansi cucumber

5
推荐指数
1
解决办法
1万
查看次数

除了Java之外,CodenameOne是否支持其他JVM语言?

CodenameOne支持将Java代码编译为本机iOS二进制文件.它是否支持其他基于JVM的语言,如Clojure或Jruby?

jvm jruby clojure ios codenameone

5
推荐指数
1
解决办法
240
查看次数

SASS正在使用反斜杠前置unicode内容(\)

问题

我正在尝试在编译*.scss文件后生成一些unicode字符.

举个例子,我有以下(SCSS):

.element:after {
    content: "\a0";
}
Run Code Online (Sandbox Code Playgroud)

编译文件时,它输出以下(CSS):

.element:after {
    content: "\\a0";
}
Run Code Online (Sandbox Code Playgroud)

注意额外的不需要的反斜杠(\).

尝试解决方案#1

我在这里尝试了解决方案:Sass:unicode转义没有保存在.css文件中,这表明引入了以下功能:

@function unicode($str) {
    @return unquote("\"")+unquote(str-insert($str, "\\", 1))+unquote("\"")
}
Run Code Online (Sandbox Code Playgroud)

像这样使用它(SCSS):

.element:after {
    content: unicode("a0");
}
Run Code Online (Sandbox Code Playgroud)

但是,这会产生以下(CSS)

.element:after {
    content: "\\" ")+unquote(str-insert($str, " \\\\ ", 1))+unquote(" \\ ""; 
}
Run Code Online (Sandbox Code Playgroud)

请注意,它甚至没有按预期调用该函数.这是为什么?

项目细节

我在Maven中使用这些库:

<dependency>
    <groupId>net.jawr</groupId>
    <artifactId>jawr-core</artifactId>
    <version>3.9</version>
</dependency>

<dependency>
    <groupId>net.jawr.extensions</groupId>
    <artifactId>jawr-spring-extension</artifactId>
    <version>3.9</version>
</dependency>

<dependency>
    <groupId>com.darrinholst</groupId>
    <artifactId>sass-java-gems</artifactId>
    <version>3.4.20.0</version>
</dependency>

<dependency>
    <groupId>org.jruby</groupId>
    <artifactId>jruby-core</artifactId>
    <version>9.1.5.0</version>
</dependency>

<dependency>
    <groupId>org.jruby</groupId>
    <artifactId>jruby-stdlib</artifactId>
    <version>9.1.5.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

临时解决方案

不要在SCSS中使用unicodes.相反,在HTML中使用Font Awesome(在CSS文件中保留Font Awesome).

css java unicode jruby sass

5
推荐指数
1
解决办法
625
查看次数

MRI Ruby和jRuby之间的性能差异

虽然做了一些基准来回答这个约来连接阵列我感到惊讶的是,当我在使用JRuby也做了同样的基准测试是慢了很多的最快方法问题.

这是否意味着关于jRuby比MRI Ruby更快的旧的慢板已经消失了?或者这是关于如何在jRuby中处理数组?

这里的基准测试结果和MRI Ruby 2.3.0和jRuby 9.1.2.0两者都运行在64位Windows 7盒子上,所有4个处理器忙于50-60%,内存使用±5.5GB.必须使用参数启动jRuby -J-Xmx1500M以提供足够的堆空间.由于堆栈级别太深,我不得不使用push删除测试,并且还删除了最慢的方法,使测试时间不长.使用Jave运行时:1.7.0_21

require 'Benchmark'
N = 100

class Array
  def concat_all 
    self.reduce([], :+)
  end
end

# small arrays
a = (1..10).to_a
b = (11..20).to_a
c = (21..30).to_a

Benchmark.bm do |r|
  r.report('plus       ')  { N.times { a + b + c }}
  r.report('concat     ') { N.times { [].concat(a).concat(b).concat(c) }}
  r.report('splash     ') { N.times {[*a, *b, *c]} }
  r.report('concat_all ')  { N.times { [a, b, c].concat_all }}
  r.report('flat_map   ') { N.times {[a, …
Run Code Online (Sandbox Code Playgroud)

ruby benchmarking rubinius jruby

5
推荐指数
1
解决办法
1293
查看次数