简体   繁体   English

将Java包分配给JRuby类

[英]Assigning a Java package to a JRuby class

(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. 在本学期的Java课程中,我们的讲师正在为我们提供已完成的实验室应该通过的已编译的JUnit测试。 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. 这是一个非常简单的Java代码,为了给自己带来更多挑战,因为我以前有过Java经验,在使用Java完成它们之后,我想在JRuby中完成所有的任务。 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. 我唯一的问题是所有已编译的测试都在java112.labsX包中,我找不到如何将JRuby类分配给Java包的参考。

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: 如果有人感兴趣,这是JRuby中的代码:

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 https://gist.github.com/789131

This gist shows using JRuby's "javac" compile mode to generate real Java classes. 这个要点显示使用JRuby的“javac”编译模式来生成真正的Java类。 You can specify packages, interfaces to implement, signatures, and so on. 您可以指定包,要实现的接口,签名等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM