Search code examples
javaeclipsejvmclasspathceylon

How do I run Ceylon Eclipse projects from the terminal?


I wrote a simple Hello World program with the Ceylon Eclipse plugin:

Ceylong Eclipse screenshot Here is the source code, in case anybody wants to reproduce the issue quickly:

shared void main() {
    String omg = (process.arguments.first else "nothing");
    print("You wrote ``omg``, you silly programmer!");
}

Now, I can run this program just fine from within Eclipse. But how do I run it from the terminal?

I don't have the Ceylon command line tools installed, and I would prefer it to stay that way. When I give my program to other people, I don't want them having to install Ceylon either.

There seems to be only one class file:

~/workspace/saloon $ find . -type f -name "*.class"
./.exploded/main_.class

If I try to run that, I get:

~/workspace/saloon/.exploded $ java main_
Exception in thread "main" java.lang.NoClassDefFoundError: ceylon/language/process_
    at main_.main(main.ceylon)
Caused by: java.lang.ClassNotFoundException: ceylon.language.process_
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

The Eclipse project does not seem to depend on any .jar files, only one .car file, but java does not work with .car files. Running Scala Eclipse projects from the terminal is easy peasy by providing the appropriate .jar files.

So how do I run Ceylon Eclipse projects from the terminal via java? Or is this impossible?


Solution

  • Well there are two possible answers depending on how much work you're willing to do.

    My first answer would be: you can't, you need Ceylon installed. Because Ceylon is not just about a program with a nice new syntax running on the JVM. It's a platform, it has its own libraries and a module system that will download dependencies on-the-fly etc. For that to work you need more than just the compiled code.

    After installing the CLI tools you'd run your program using : ceylon run <name-of-your-module>

    My second answer would be: if you really want to be able to run independent from the Ceylon platform and are willing to forgo the tools and the module system etc and are willing to go through the trouble of collecting the necessary dependencies and distribute them along with your program yourself then you can use the ceylon classpath <name-of-your-module> command to get a list of all the dependencies your program is using.

    You can then run it using the com.redhat.ceylon.compiler.java.runtime.Main entry point.

    A detailed explanation of that can be found here on the website: http://www.ceylon-lang.org/documentation/1.1/reference/interoperability/ceylon-on-jvm/