I recently spent several frustrating days trying to get some JRuby code to call some Java classes. The problem seemed to be that the individual Java classes required some jars that weren't on the JRuby classpath, although they were on the classpath for the Java project they belonged to. I still haven't figured out the proper way to fix that, and the only solution I've found so far is to include the following line in my JRuby code:
"$CLASSPATH << path/to/something.jar"
This includes the required jar in the JRuby classpath. I'd really like to be able to just give a -cp (or similar) command to the JRuby interpreter, but haven't been able to figure out what that would be yet.
The next issue was that there were some dlls required by the Java class. I'm still not sure why, since when the Java project is run independently it isn't necessary to tell the JVM where the dlls are, but when the classes are called individually the dlls aren't found, leading to problems. The only way I could find to fix this problem is to include the following line in my Java class:
"System.load(path/to/myDLL.dll)"
Now the entire thing is up and running, but I wish there were a better way to solve these problems. It took me a while to even get this far, so hopefully someone else having the same problem will find this helpful.
skip to main |
skip to sidebar
Saturday, January 3, 2009
Subscribe to:
Post Comments (Atom)
Kate...
Archive
Labels
- #picmecomp (1)
- books (21)
- career (18)
- computer geekdom (40)
- conferences (39)
- datamining (8)
- frisbee (3)
- games (5)
- ghc08 (5)
- ghc10 (3)
- ghc11 (15)
- ghc12 (13)
- ghc13 (9)
- graduate school (23)
- iPhone (5)
- languages (1)
- LaTeX (3)
- life on a mountain (19)
- linux (3)
- movies (1)
- music (5)
- photography (6)
- programming (19)
- radio (4)
- robotics (21)
- scholarships (10)
- science fiction (33)
- science news (19)
- travel (54)
- windows phone (4)
- Women in Computing Science (65)
2 comments:
If you set the CLASSPATH environment variable before launching JRuby, JRuby will honor it, adding its own classes/jars to those that are already in the classpath. That's probably the easiest way to avoid hard-coding paths in your script.
You can also use the "-J" argument prefix to pass arguments to the JVM.
I must be doing something wrong - I tried setting the CLASSPATH environment variable but it didn't work.
I tryed using -J and that didn't work either. -J-cp=""? It didn't recognize it. Maybe I have the part that follows -J wrong?
Thanks so much for your help!
Post a Comment