Assigning a Java Package to the JRuby Class

(This is not a domestic matter, as it is above and above class only for my personal interests.)

In my Java class this semester, our instructor gives us compiled JUnit tests that our completed labs must pass. For example, our first laboratory was to create this class:

package java112.labs1; public class MysteryClassOne { public int mysteryMethodOne() { return 1; } } 

This is very trivial Java code and a little more complicated for me, since I had previous Java experience, I would like to complete all assignments in JRuby after they are completed in Java. My only problem is that all compiled tests are in the java112.labsX package, and I cannot find a link to how to assign the JRuby class to the Java package.

There you have it, in my typical deep-rooted way.

EDIT

Thanks to headius below for solving this problem. Here is the code in JRuby, if anyone is interested:

 require 'java' java_package 'java112.labs1' class MysteryClassOne java_signature 'int mysteryMethodOne()' def mysteryMethodOne return 1 end end 
+4
source share
1 answer

You might be interested in something like this:

https://gist.github.com/789131

This gist shows using JRuby "javac" compilation mode to generate real Java classes. You can specify packages, interfaces for implementation, signatures, etc.

+3
source

Source: https://habr.com/ru/post/1336102/


All Articles