将Java包分配给JRuby类 [英] Assigning a Java package to a JRuby class

查看:72
本文介绍了将Java包分配给JRuby类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这不是家庭作业的问题,因为出于我个人的利益,它超出了班级范围.)

(This isn't a homework question, as it's above and beyond the class just for my personal interest.)

在本学期的Java课堂中,我们的讲师正在为我们提供已完成的实验应通过的已编译JUnit测试.例如,我们的第一个实验室就是设计此类:

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;
    }
}

这是非常琐碎的Java代码,给我带来更多挑战,就像我以前的Java经验一样,在Java中完成所有分配后,我想在JRuby中完成所有分配.我唯一的问题是所有编译后的测试都在java112.labsX包中,并且找不到如何将JRuby类分配给Java包的参考.

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.

编辑

以下感谢您解决此问题的方法.如果有人感兴趣,这是JRuby中的代码:

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

该要点显示了使用JRuby的"javac"编译模式来生成实际的Java类.您可以指定包,要实现的接口,签名等.

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.

这篇关于将Java包分配给JRuby类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆