(This isn't a homework question, as it's above and beyond the class just for my personal interest.)
In my Java class this semester, our instructor is giving us the compiled JUnit tests that our completed labs should pass. For example, our first lab was to design this class:
package java112.labs1;
public class MysteryClassOne {
public int mysteryMethodOne() {
return 1;
}
}
This is very trivial Java code and to give myself a bit more of a challenge as I've had previous Java experience, I'd like to do all of the assignments in JRuby, after completing them in Java. My only issue is all of the compiled tests are in the java112.labsX package and I can find no reference for how to assign a JRuby class to a Java package.
There you have it, in my typical long-winded fashion.
EDIT
Thanks to headius below for solving this issue. Here's the code in JRuby if anyone's interested:
require 'java'
java_package 'java112.labs1'
class MysteryClassOne
java_signature 'int mysteryMethodOne()'
def mysteryMethodOne
return 1
end
end
Perhaps you're interested in something like this:
https://gist.github.com/789131
This gist shows using JRuby's "javac" compile mode to generate real Java classes. You can specify packages, interfaces to implement, signatures, and so on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.