I have a java shell application. I recently brought it back, the main
reason being to see what was going on with all this new java scripting
stuff like invokedynamic. Sort of got it working with some functionality
for JRuby 1.6.7.
Recent talk about performance and invokedynamic got me to thinking maybe
I'd get current and go from there.
I had googled up some stuff and had tried to add a jirb command into the
application. That currently is run off this
public static void main(final String[] args) {
final ConsoleInterface console = CommandLine.getConsole();
final Jirb jirb = new Jirb();
Thread.currentThread().setContextClassLoader(jirb.getClass().getClassLoader());
final RubyInstanceConfig config = new RubyInstanceConfig() {{
setInput(console.getIn());
setOutput(System.out);
setError(System.out);
setArgv(args);
}};
final Ruby runtime = Ruby.newInstance(config);
runtime.getGlobalVariables().defineReadonly("$$", new
ValueAccessor(runtime.newFixnum(System.identityHashCode(runtime))));
runtime.getLoadService().init(new ArrayList());
hookIntoRuntime(runtime,jirb);
if (runtime.getClass("HP") == null) {
runtime.evalScriptlet(
"class HP\n"
+"require 'java'\n"
+"def hp(*cmd)\n"
+" _ps = org.cmdline.cmdIO.ArrayCmdOut.getInstance()\n"
+"
org.cmdline.psuedoGestalt.CommandShell.new.command(cmd.join(\"
\"),true,_ps,_ps);\n"
+" _result = _ps.getOutput()\n"
+"end\n"
+"\n"
+"def hpQ(*cmd)\n"
+" _ps = org.cmdline.cmdIO.QueueCmdOut.getInstance()\n"
+"
org.cmdline.psuedoGestalt.CommandShell.new.command(cmd.join(\"
\"),true,_ps,_ps);\n"
+" _result = _ps.getOutput()\n"
+"end\n"
+"end"
);
}
The application is called HalfPipe, since it sometimes seems like I'm
just using it to do new skateboarding tricks. But from that, came the HP
class which is supposed to be glue code to allow the ruby code command
line API type access back into the application shell.
So you could do something like
halfpipe = HP.new
halfpipe.hp("exec jps");
This worked fine 1.6.7 but at 1.7.2 I get
jirb
org.jruby.exceptions.RaiseException: (NameError) ArrayJavaProxy is
already defined
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1027)
at
RUBY.require(/Library/Frameworks/JRuby.framework/Versions/Current/lib/ruby/shared/rubygems/custom_require.rb:36)
at RUBY.HP(<script>:2)
at RUBY.(root)(<script>:1)
Would anyone have any thoughts what might be different and how I should
now work this?
Michael Hall
trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz
HalfPipe Java 6/7 shell app
http://www195.pair.com/mik3hall/index.html#halfpipe
AppConverter convert Apple jvm to openjdk apps
http://www195.pair.com/mik3hall/index.html#appconverter
on 2013-01-27 16:53
on 2013-01-28 12:50
On Jan 27, 2013, at 9:51 AM, Michael Hall wrote: I commented out this line and it is now working at 1.7.2, haven't back tested 1.6.7. > runtime.getLoadService().init(new ArrayList()); If anyone curious, it looks like this working jirb Switch to inspect mode. irb(main):001:0>halfpipe = HP.new #<HP:0x65eee8c> irb(main):002:0>halfpipe.hp("exec jps") #<Java::JavaUtil::ArrayList:0x3eec44a6> irb(main):003:0>jprocs = halfpipe.hp("exec jps") #<Java::JavaUtil::ArrayList:0x5302b9f7> irb(main):004:0>jprocs[0] "1566 Jps" irb(main):005:0>quit exec jps 1567 Jps 1313 1543 LoaderLaunchStub exec ls -l /Library/Frameworks/JRuby.framework/Versions/Current lrwxr-xr-x 1 root wheel 50 Jan 28 05:22 /Library/Frameworks/JRuby.framework/Versions/Current -> /Library/Frameworks/JRuby.framework/Versions/1.7.2 (exec is of course Runtime exec, there are other commands). Michael Hall trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.