mingw / git bash shell 中的 jRuby 问题

发布于 2024-11-14 19:34:19 字数 1308 浏览 4 评论 0 原文

我在 Windows 中从 mingw git bash shell 执行 jruby 时遇到问题。我下载了 jruby 1.6.2 的 Windows 安装程序并运行它没有问题。如果我打开一个新的 Windows cmd shell,它似乎工作正常。我安装了 rake 和 sinatra gems;使用了irb。输入 jruby -v 获取:

jruby 1.6.2 (ruby-1.8.7-p330) (2011-05-23 e2ea975) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]

但是,当我打开 git mingw bash shell 并尝试对 jruby 执行任何操作时,我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.jruby.Main.  Program will exit.

我已确保 jruby lib 目录位于类路径中。

还有其他想法吗?

更新: 我认为问题在于 shell 脚本最终调用 jruby bin 目录中的 jar。

问题是,虽然 msys 可以将 POSIX 转换为 Win 路径,但该脚本会自行构建字符串,以便将类路径和其他信息传递给 jar。

看来这就是事情变得混乱的地方。出于同样的原因,这些脚本特别具有处理 cygwin 的代码分支。我试图强制脚本认为它是在 cygwin 下运行,但不幸的是,脚本使用“cygpath”程序来获取路径,而这在 msys 中不可用

I'm having an issue executing jruby from the mingw git bash shell in windows. I downloaded the windows installer for jruby 1.6.2 and ran it without issue. If I open a new windows cmd shell it seems to work fine. I installed the rake and sinatra gems; used the irb. entering jruby -v gets:

jruby 1.6.2 (ruby-1.8.7-p330) (2011-05-23 e2ea975) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]

However, when I open the git mingw bash shell and attempt to do anything with jruby I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.jruby.Main.  Program will exit.

I have made sure that the jruby lib directory is in the classpath.

Any other ideas?

UPDATE:
I think the issue is the shell scripts that end up invoking the jar in the jruby bin directory.

The issue is that while msys can transform POSIX to Win paths for most things, but the script builds up strings on its own in order to pass classpath and other information to the jar.

It appears that this is where things are getting messed up. The scripts specifically have branches of code that deal with cygwin for this same reason. I attempted to force the scripts to to think that it was running under cygwin but unfortunately the scripts make use of the "cygpath" program to get the paths and that is not available in msys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮光沉寂 2024-11-21 19:34:19

事实证明这确实是 bash 脚本的“缺失功能”。我向 jruby jira 提交了一个错误,并已解决

https://jira.codehaus.org/browse /JRUBY-5864

请注意,截至撰写本文时,该提交尚未成为可在 jruby 网站上下载的构建的一部分。但修复方法非常简单。

这是提交: https://github.com/jruby/jruby/commit/8766f84b774ae5ae68204931bd4eab61b81a2056

就是将以下内容添加到 jruby.bash 文件顶部的 uname 大小写中

MINGW*) jruby.exe "$@"; exit $?;;

Turns out is was indeed a "missing feature" of the bash scripts. I submitted a bug to the jruby jira and it was resolved

https://jira.codehaus.org/browse/JRUBY-5864

Note that as of the time of this writing that commit has not been part of the build that's available for download on the jruby web site. But the fix was quite simple.

Here is the commit: https://github.com/jruby/jruby/commit/8766f84b774ae5ae68204931bd4eab61b81a2056

All it is is adding the following to the uname case at the top of the jruby.bash file

MINGW*) jruby.exe "$@"; exit $?;;
柠檬 2024-11-21 19:34:19

诀窍是,mingw shell 可能不会从 Windows 环境继承所有环境变量。
因此,如果 java -jar lib/jruby.jar -e "puts 'hello 在 jruby 目录中工作,那么:

java -jar /full/path/to/jruby/lib/jruby.jar -e "puts 'hello

也应该工作。
如果没有,请仔细比较两组环境变量(正常的 DOS shell,它可以工作,而 mingw shell,它不能工作)。


它也可以像 mingw 环境中类路径的语法差异,如 在此线程中说明

您的问题不是路径未正确传递;而是路径未正确传递。就是你根本没有允许它通过。
键入时,您的命令行包含一个不带引号的分号; 在任何 Bourne 兼容 shell 中,例如
在 bash 中,不带引号的分号首先充当命令终止符,然后充当命令分隔符
,因此您的命令行相当于两个单独的命令:

$ java.exe -classpath .
$ $DIR hello

[警告:我这里没有 Windows 盒子;以下未经测试]

您需要引用分号,AND(因为您现在引入了一个代表Win32本机格式的路径列表的参数,因此它将免于翻译,您需要确保DIR也定义为 DIR=d:/myClasses 而不是 DIR=/d/myClasses):

$ java.exe -classpath .\;$DIR hello

或者,您需要完全以 UNIX 格式指定路径列表(即使用冒号而不是分号作为单独的路径分隔符):

$ java.exe -classpath .:$DIR hello 

The trick is, a mingw shell might not inherit all environment variables from the Windows environment.
So if a java -jar lib/jruby.jar -e "puts 'hello works within the jruby directory, then:

java -jar /full/path/to/jruby/lib/jruby.jar -e "puts 'hello

ought to work as well.
If not, carefully diff the two set of environment variables (normal DOS shell, where it works, and mingw shell where it doesn't)


It could also be as simple as a difference of syntax for the classpath in a mingw environment, as illustrated in this thread:

Your problem is not that the path isn't being passed correctly; it is that you haven't allowed it to be passed at all.
As typed, your command line includes an unquoted semicolon; in any Bourne compatible shell such
as bash, the unquoted semicolon acts first as a command terminator and then as a command separator
, so your command line becomes equivalent to the two separate commands:

$ java.exe -classpath .
$ $DIR hello

[Caveat: I don't have a Windows box here; the following is untested]

You need to quote the semicolon, AND (because you have now introduced a parameter which represents a path list in Win32 native format, so it will be exempt from translation, you need to ensure that DIR is ALSO defined as DIR=d:/myClasses NOT as DIR=/d/myClasses):

$ java.exe -classpath .\;$DIR hello

OR, you need to specify the path list entirely in UNIX format, (i.e. with a colon NOT a semicolon as the individual path separator):

$ java.exe -classpath .:$DIR hello 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文