无法导入任何java类

时间:2014-10-23 15:43:40

标签: ceylon

HelloWorld.ceylon

import java.util { HashMap } //Error:(1, 8) ceylon: package not found in imported modules: java.util (define a module and add module import to its module descriptor)

void run() {
    print("test");

}

module.properties

module CeylonHelloWorld "1.0" {
    import java.base "8";
}

我在HelloWord.ceylon文件中得到一个例外

3 个答案:

答案 0 :(得分:1)

当我尝试该代码时,我得到:

Incorrect syntax: mismatched token CeylonHelloWorld expecting initial-lowercase identifier

module.ceylon

模块的名称应该是foo.bar.baz形式(初始 - 小写标识符以句点分隔)。

答案 1 :(得分:0)

如同Gavin所提到的,你必须使用合法的模块名称,当我更改你的代码以使用模块名称“java8test”时,我在编译时得到以下输出:

$ ceylon compile java8test
warning: It looks like you are using class files from a Java newer than 1.7.
  Everything should work well, but if not, let us know at https://github.com/ceylon/ceylon-compiler/issues.
  In the near future, the Ceylon compiler will be upgraded to handle Java 1.8.
./source/java8test/run.ceylon:1: warning: import is never used: 'HashMap'
import java.util { HashMap }
              ^
2 warnings
Note: Created module java8test/1.0.0

这一切都符合预期。

答案 2 :(得分:0)

<强> module.ceylon

module holaCeylon "1.0.0"{
    import java.base "7"; // versión 7  JDK
}

<强> package.ceylon

shared package holaCeylon;

现在我们回到run.ceylon文件并导入java.util.HashMap Java库。

<强> run.ceylon

import  java.util  { HashMap }

shared void run(){
   print("Importando librerias de Java en Ceylon"); 
   value romanos = HashMap<String,Integer>();
    romanos.put("I", 1);
    romanos.put("V", 5);
    romanos.put("X", 10);
    romanos.put("L", 50);
    romanos.put("C", 100);
    romanos.put("D", 500);
    romanos.put("M", 1000);
    print(romanos.values());
    print(romanos.keySet());
}

输出: salida

代码: http://codemonkeyjunior.blogspot.mx/2015/03/ceylon-interoperabilidad-con-java.html