Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write web applications using Ceylon?

Ceylon hitting 1.0 caught my attention lately. The most interesting feature is that it can be compiled for both the JVM and Javascript engines (node.js, browsers) so it makes code sharing possible from the beginning between the server backend and web application running in the browser.

I've started looking up the documentation for details how to create a WAR deployable application with Ceylon where i have some REST endpoints serving stuff to the browser side. I was not expecting Spring WebMVC support although this would be my final goal. For my surprise i didn't find anything useful in this topic. Is there any recommendations how to use Ceylon when i try to target a Servlet engine like Jetty or Tomcat the way i've described?

Right now i'm doing the following in a Java application:

  • Create a Maven webapp project
  • Put JQuery Javascript client code and other static stuff to src/main/webapp
  • Write some Spring MVC controllers to server JSON resources

A similar thing would be great where the client code is transposed from Ceylon code aswell. As i see Ceylon uses it's very own project layout and build system although i would be more happy to use Maven or Gradle to not steer away too much from existing projects.

like image 290
NagyI Avatar asked Nov 18 '13 10:11

NagyI


1 Answers

Now that the language and its compilers have hit 1.0, we're able to shift some of our attention to development of things like web frameworks. Right now, Ceylon doesn't have a finished web framework.

What it does have is:

  1. A simple HTTP server based on JBoss Undertow, as part of the module ceylon.net. This makes it really easy to create a little web server, especially in conjunction with ceylon.html for rendering HTML pages.
  2. Julien Viet's vert.x bridge and promises module, which provide a wrapper for vert.x.
  3. A cartridge for Red Hat's OpenShift, that lets you deploy a Ceylon web application on Red Hat's cloud.

I understand that this is not a full solution to your question of how can you run Ceylon on a traditional servlet engine. The truth is that you actually can take a compiled Ceylon module archive, embed it in a .war and use it inside Tomcat or Jetty or JBoss or whatever. A .car is, after all, just a .jar with some extra metadata. The problem with that is that you will lose the advantages of Ceylon's module runtime that you usually have when you use ceylon run. You'll need to:

  • manually make sure all the dependencies your module uses are are available in the .war, and
  • you won't get the classloader isolation.

If you can live with that, then, go for it. It will work. But from my point of view the vision we have is to get away from the legacy servlet engines and run something like Undertow (ceylon.net) or vert.x on top of the module runtime. Remember that this "module runtime" we're talking about is anyway just JBoss Modules, the tiny core of JBoss itself.

like image 84
Gavin King Avatar answered Sep 17 '22 17:09

Gavin King