Visual Studio Code for Play Framework Project
Play Framework is Java based web framework that promises to be the asynchronous framework that competes with another non-blocking web framework. That is my own word. Officially, Play Framework says as follow,
Play Framework — The High Velocity Web Framework
The Play Framework combines productivity and performance making it easy to build scalable web applications with Java and Scala. Play is developer friendly with a “just hit refresh” workflow and built-in testing support. With Play, applications scale predictably due to a stateless and non-blocking architecture. By being RESTful by default, including assets compilers, JSON & WebSocket support, Play is a perfect fit for modern web & mobile applications.
That’s cited from its official GitHub repository README!
Here you’ll learn how to setup VSCode for Play Framework based app development.
There are some problems that still occur in my machine. If you know how to fix it, please share it in comment. I’ll show it soon.
Officially Play Framework gives 3 options for our editor tools. Those are Eclipse, IntellijIDEA, and NetBeans. With those IDE, you’ll have all the power of Java support editor including completion, syntax highlight, package resolution, etc.
To me there is no problem of using those tools except IntellijIDEA need Ultimate version to use its Play support. The others I am not happy to work with except in great need. I am lover of enterprise tools, not to mention my background is iOS developer which Apple’s Xcode is my main tool to develop software. Scala IDE which based on Eclipse doesn’t have good experience to me.
That’s why I move to Visual Studio Code. Wait.. what?
Yes, although VSCode just an editor compared with JetBrains’s products but its power in software development cannot be ignored. And Microsoft has officially supported Java apps development by putting Java extension pack in VSCode marketplace. There are also some Java extension from well-known company. That’s nearly enterprise solution. Ahaha. And free.
Too much talk. Let’s do the real dirty job.
First you need to create your Play apps. Here we’ll use Java rather than Scala for main language.
sbt new playframework/play-java-seed.g8
Change the application root directory. cd <your-play-apps>
Add this to your plugins.sbt
file.
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.2")
Or you can refer to Play Framework official web page to use the most recent version of the plugin. This will turn your project to Eclipse compatible project which VSCode can read
and use it’s Java power.
Now run this command before open project in VSCode.
sbt compile && sbt eclipse
If you have no error, then you can start use your VSCode to write your apps with full Java language server power.
Problem?
I’ve mentioned earlier that there is problem in my machine. From your fresh project, open HomeController.java
in controllers
. You’ll see curly red lines as usual indication of error. But if you run command sbt run
and access localhost:9000/
in browser, there will be no error thrown.
Yes, the problem to me is the red line. That’s tickling me to get rid of it. Fortunately, I don’t write web application but RESTful API.
Keep coding!