Play 2.5.x in Docker container not updating through shared folder - scala

I'm running a development environment for Play Framework 2.5.x in a Docker container. The application works, and I can view it on my browser through the shared port. However, the auto-update feature does not work.
From research I've learned this is because Play's JNotify doesn't poll file changes in shared folders. I've tried the solution to this problem, which is simply polling at a time interval by adding the following to build.sbt
PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(pollInterval.value)
After making this change (and making sure it was pushed through the shared folder), using activator run successfully compiles and runs the server.
[info] Done updating.
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
I can view it in my browser. However, on changing a file, no recompilation happens and refreshing doesn't change anything. Stopping and starting the server however does show the change.
I think I may know why, but I don't know how to solve it. I've read that using activator ~run supposedly starts the server, but uses SBT instead of activator. When I use this command to start the server, it hangs at:
[info] Set current project to example-user-app in build file:/home/example-user/example-user-app)

Related

How to run sbt-revolver with a Scala project?

So I'm reading the documentation for sbt-revolver since I'm interest in using its:
Triggered restart: automatically restart your application as soon as some of its sources have been changed
It says in the documentation that it should work with any scala project ( I'm running an Akka Http) as long as it has a class with a main method and that we just need to plug in project/plugins.sbt:
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.0")
So I did that then I went with terminal to root folder, ran sbt wait it to load and then run, now I made a small change in some file that loads and html with some <h1> but changes aren't reloaded, what am I missing?
Update
So after running sbt in terminal, then I run ~reStart and it seems to exit the server:
root Server online at localhost:8080 root Press RETURN to stop... root ...
finished with exit code 0
You have two options, if you need only run, no need the revolver plugin, just start it with
~run
If you need revolver, you should use
~reStart
as it is stated on their homepage too:
You can use ~reStart to go into "triggered restart" mode. Your application starts up and SBT watches for changes in your source (or resource) files. If a change is detected SBT recompiles the required classes and sbt-revolver automatically restarts your application.
Note, you can specify any command to be run on each change of source files after ~.

How to stop maven tomcat

I am very new to Maven builds. I have created a maven project and running it using maven build. It is running fine using tomcat7:run as goal but then I am finding it hard to stop the server. I am getting following error when I try to run again.
java.net.BindException: Address already in use: JVM_Bind <null>:8080
Any suggestions ?
If the process is still running, you should be able to see it in your console. If you see a stop button (like 1), just press it and that should stop the tomcat server.
If you happen to have had more than one service running, then the button in 2 should be activated. That will show all the running and stopped services you have. Select the one for your Tomcat and then press the stop button.
You can use mvn tomcat7:shutdown command to stop.
Shuts down all possibly started embedded tomcat servers. This will be automatically down through a shutdown hook or you may call this Mojo to shut them down explictly.
Here is the documentation.

Immediately Restarting Play Framework's Development Server on Code Change (without First Requiring a Web Request)

Is there a way to run Play's development server (started with run) such that it compiles and starts the server immediately upon a code change without having to receive a web request?
Various modes, by contrast, behave as follows:
run will compile and restart on web request after code change.
~run will compile immediately on code change and restart after web request.
start (now testProd) and ~start will compile and start immediately (with undesirable API doc. overhead) with no restarts after code change.
An approximation of the behavior I'm wanting would be to run watch -n 1 curl http://localhost:9000 in the background.

xsbt-web-plugin Running the web servelet container outside of sbt?

I'm using the xsbt-web-plugin to host my servelet. It works fine, using container:start.
I now need it to run in the background, like a daemon, even if I hang up, and ideally, even if the machine reboots. I'd rather not have to invoke sbt.
I know that the plugin can package a WAR file, but I'm not running tomcat or anything like that. I just want to do what container:start does, but in a more robust (read: noninteractive) way.
(My goal is for a demo of dev: I'd hate for my ssh session to drop sbt, or something similar like that, while people are using the demo. But we're not ready for production yet and have no servelet infrastructure.)
xsbt-web-plugin is really not meant to act as a production server (with features like automatic restarting, fault recovery, running on boot, etc.), however I understand the utility of using it this way for small-scale development purposes.
You have a couple of options:
First approach
Run sbt in a screen session, which you can (dis)connect at will without interrupting sbt.
Second approach
Override the shutdown function that triggers on sbt's exit hook, so that the container keeps running after sbt stops.
For this approach, add the following setting to your sbt configuration:
build.sbt:
onLoad in Global := { state => state }
Note that this will override the onLoad setting entirely, so in the (unlikely) case that you have it configured to do other important things, they won't happen.
Now you can launch your container either by running container:start from sbt and then exiting sbt, or simply by running sbt container:start from the command line, which will return after forking the container JVM. Give it a few seconds, then you should be able to request to localhost:8080.

Scala Play Framework application doesn't restart properly after changing sources

I have a Play 2.2 application written in Scala that starts and runs properly (using play run). Recently, however, it began to have trouble restarting correctly after discovering source file changes.
The application used to rebuild and restart automatically when it detected changes to source files. Play still detects source changes and attempts to restart the server, however it only makes it as far as stopping it - it's not restarted correctly.
Here's what play run looks like in the console:
[info] Loading project definition from <path>
[info] Set current project to GTF (in build file:<path>)
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
[info] play - database [default] connected at jdbc:mysql://localhost/mydb
[info] application - START
[info] play - Starting application default Akka system.
[info] play - Application started (Dev)
So far, so good. The application is started and running properly at this point. However, if I change a source file and refresh the page, the following shows up in the console:
[info] Compiling 1 Scala source to <path>...
--- (RELOAD) ---
[info] application - STOP
[info] play - Shutdown application default Akka system.
And that's it. It seems to compile/build, but it never gets to application - START. The browser window just sits there perpetually loading the page.
I have tried play clean and play clean-all, but that didn't solve the problem. I've also tried running the application with a tilda, like so: play ~run (this was suggested elsewhere), but that didn't work either. Any ideas? Again, it's very puzzling because it used to work properly. This issue makes development rather annoying, since I have to restart the server manually each time I change any source file. Thanks.
Shouldn't you be using "play ~run"? The Play application shouldn't need to restart to compile and apply your changes.