Trying to embed jruby within an app in onejar

I’m embedding jruby into a ruby scriptrunner I want to deliver in
onejar (http://one-jar.sourceforge.net/). As an exploded set of
classes on disk, my runner class works just fine. When packaged up in
a onejar (using jrubycomplete.jar), I’m getting a stack trace when I
run my script:
Exception in thread “main” java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.simontuffs.onejar.Boot.run(Boot.java:247)
at com.simontuffs.onejar.Boot.main(Boot.java:105)
Caused by: java.lang.NullPointerException
at
com.kenai.constantine.Platform.getPackageName(Platform.java:39)
at
com.kenai.constantine.ConstantSet.getEnumClass(ConstantSet.java:84)
at
com.kenai.constantine.ConstantSet.getConstantSet(ConstantSet.java:60)
at
com.kenai.constantine.platform.ConstantResolver.getConstants(ConstantResolver.java:181)
at
com.kenai.constantine.platform.ConstantResolver.getConstant(ConstantResolver.java:102)
at
com.kenai.constantine.platform.ConstantResolver.intValue(ConstantResolver.java:146)
at
com.kenai.constantine.platform.OpenFlags.value(OpenFlags.java:28)
at org.jruby.RubyFile.createFileClass(RubyFile.java:251)
at org.jruby.Ruby.initCore(Ruby.java:1268)
at org.jruby.Ruby.bootstrap(Ruby.java:1096)
at org.jruby.Ruby.init(Ruby.java:1074)
at org.jruby.Ruby.newInstance(Ruby.java:177)
at
org.jruby.embed.internal.LocalContext.getRuntime(LocalContext.java:70)
at
org.jruby.embed.internal.SingletonLocalContextProvider.getRuntime(SingletonLocalContextProvider.java:56)
at
org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.runParser(EmbedRubyRuntimeAdapterImpl.java:163)
at
org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:101)
at
org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1097)
at
org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1164)
at
com.xxx.lds.buildtools.EmbeddedRubyRunner.rubyEval(EmbeddedRubyRunner.java:144)
at
com.xxx.lds.buildtools.EmbeddedRubyRunner.rubyEval(EmbeddedRubyRunner.java:98)
at
com.xxx.lds.buildtools.EmbeddedRubyRunner.main(EmbeddedRubyRunner.java:33)
… 6 more

I know that it is finding my script as I have debugged through it. The
problem is within the com.kenai.constantine packages, so I grabbed the
com.kenai.constantine source from github, traced through three places
in which I was getting a null pointer exception when within a onejar
package, and got it working.

Platform.getPackageName() was implemented like this:
return String.format("%s.platform.%s.%s",
Platform.class.getPackage().getName(), OS, ARCH);

and it appears that Platform.class.getPackage() is returning null
(hmm… now that I think if it, I didn’t validate that Platform.class
isn’t null…). Anyway, I was able to fix it by simply hardcoding
Platform’s package here:

return String.format("%s.platform.%s.%s", “com.kenai.constantine”, OS,
ARCH);

And after fixing 3 instances of this (Two in
com.kenai.constantine.Platform and one in
com.kenai.constantine.ConstantSet), it runs fine from within my jar
and outside of the jar as classes on disk.

So… I have a couple of questions:

a) Why did they go the “sophisticated” route of getting the package
name, is there some crazy case in which that could be dynamically set?
b) Is this really the right list to ask this question or should I be
sending this to the DEV list, instead?
c) Since this is in the com.kenai.constantine package, does the jruby
team even care and should I take it up with that project instead?

Thanks.

–rt

-------- [email protected]
----- `<,
---- ()/ ()

robert tomb

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

I had the same issue when trying to embed jruby inside extension for
Moneydance - http://github.com/arvicco/moneydance-ruby. Using the
technique described in this post resolved this issue.

You need to patch com.kenai.constantine package that is included in
jruby-complete before embedding it in another jar.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs