kandi
kandi

Reputation: 1118

Can't import any java classes

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

I get an exception in HelloWord.ceylon file

Upvotes: 0

Views: 445

Answers (3)

Fernando Carraro
Fernando Carraro

Reputation: 101

module.ceylon

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

package.ceylon

shared package holaCeylon;

Now we go back to the run.ceylon file and import the java.util.HashMap Java library.

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

Output: salida

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

Upvotes: 0

Quintesse
Quintesse

Reputation: 462

Like mentioned by Gavin you will have to use a legal module name, when I change your code to use the module name "java8test" I get the following output when compiling:

$ 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

Which is all as expected.

Upvotes: 0

Gavin King
Gavin King

Reputation: 4273

When I try that code, I get:

Incorrect syntax: mismatched token CeylonHelloWorld expecting initial-lowercase identifier

In module.ceylon.

The name of a module is supposed to be of form foo.bar.baz (initial-lowercase identifiers separated by periods).

Upvotes: 1

Related Questions