LoginSignup
3
2

More than 5 years have passed since last update.

[メモ]ScalaでコンパイルしたクラスファイルをJavaのコードがから呼び出す

Posted at

Scalaでコンパイルしたクラスファイルを、Javaのコードが呼ぶためのテスト

Scalaでコンパイル

以下のようなファイルをテスト用に用意して、コンパイル。

 object HelloWorld {
  def test() = {
    "This is the test."
  }
}

Helloworld.class含むクラスファイルが出力される。

Javaのファイルを用意
public class ScalaTest {
    public static void main(String... args){
        System.out.println( HelloWorld.test());
    }
}

先ほど作成したクラスファイルと、scala-library.jarを環境変数CLASSPATHに含めて、コンパイル、実行すればOK

 $ javac  ScalaTest.java
 $ java   ScalaTest
this is the test

以上

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2