Play! - Interacting with a webapp from the SBT console - scala

I have a Play! 2 application where I have defined some jobs. These jobs interact with external web services and with the database, hence they need a running application to work.
I would like to be able to launch these jobs as SBT tasks from the Play console. SO I have followed the guide to define my own tasks and I am able to define simple tasks. What I cannot do is importing from the application namespace. I guess this makes some sense - in the context of SBT we may not have an application running.
Is there some way to write an SBT task where an application is launched and one has access to the application namespace?

Don't know if you still need an answer, have you tried to use the Play console?
$ play console
It loads all your application classes so you can use them as you wish.
See http://www.playframework.com/documentation/2.1.0/PlayConsole for more information :)

Related

Is it possible to use typesafe activator offline?

I have tried running activator from the distribution, but even when I set the proxy configuration, it seems that there are some hosts I cannot access from behind my corporate firewall. This includes Amazon S3, which seems to be being used when I try to run the ui.
Is it possible to use activator solely from the distribution I have downloaded (which appears to contain a local ivy repository)? Currently, it does not seem that play, sbt, activator etc. are well-suited to a corporate environment. Have I missed something?
You can always use the activator terminal command. For this you'd need no internet connection. Actually I never use the activator UI unless I want to try out some examples. Run activator help from within your play application's root folder to see the list of possible commands. E.g. with activator run you'd run your application.

Google App Engine Deploy Only Jar File

I am beginner for Google App Engine.
I have simple java application with a class in which there is main method which executes some threads.
Actually, it's Java application which is used to execute some back-end activities.
On my Linux server, i have created a cron job which executes this class at some specific time interval.
Now, I want to move this application to Google App Engine.
I did search about that and what i find is i have to convert this java application to web application to deploy on GAE.
Please guide me how i can deploy JAR to GAE.
Thanks
Yes, your java application needs to be a web application. That is, you'd need to have a WEB-INFO directory within your jar, with the correct xml files (i.e. web.xml and appengine-web.xml).
Please, start by following one of the tutorials here:
https://cloud.google.com/appengine/docs/java/gettingstarted/introduction
You also mentioned that you use threads in your application. I believe that on App Engine you cannot just create threads, and instead you need to rely on the provided threads api:
https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/ThreadManager
Thus, some of your code will need to be changed to use such an api.
Finally ! i figured out the solution without using Google App Engine and just using Google Compute Engine.
I created a JAR and put it into my home folder using SFTP.
After that i created a cron file at /etc/cron.d/myfile as below
*/10 * * * * myusername java -jar /home/myusername/myjar.jar
Then i reload the crontab
sudo service cron reload
That's it ! Thanks for your input and interest !
If you mean just a simple JAR with a main method, that won't work. Your application has to be a web service that responds to requests.
Check this link to create an app using JAR file:
APP-ENGINE
You cannot deploy a single jar file to App Engine. You can deploy an application.
This tutorial explains how to create an App Engine project in Java:
https://cloud.google.com/appengine/docs/java/gettingstarted/introduction
Yes, you can only deploy web applications to Google App Engine, so you may have to convert your class into a Servlet class if you want to deploy it to App engine.
You can use the Servlet's url if you are looking to execute it as a cron job, so you can configure this url in a file cron.xml by specifying the frequency and time when cron job should be executed before deploying.
You can use the link below which will guide you through the steps :
http://www.vogella.com/tutorials/GoogleAppEngineJava/article.html
Google's documentation on Cron Job :
https://cloud.google.com/appengine/docs/java/config/cron
You can not however use threads when working with App Engine.

Deploying Play 2.3 on production

I have developed a Scala/Play webapp and now I am trying to deploy it on production.
What is the recommended "best way" of doing that?
The documentation mentions only runnig it from play console, which does not seem very robust (in case of machine restarts etc).
There are apporaches to wrap the app into a war file and deploy on Tomcat7 (e.g. play2war), but they do not seem to be actively developed (e.g. there is only beta support for 2.3, the plugin is not available from maven repo etc).
What is the right way of doing this?
If you host the application on Windows then take a look at Yet Another Java Service Wrapper which wraps the application in a Windows service that will keep it running, even after restarts.
If you run it on Linux then take a look at Supervisord and Monit, which monitors the application and starts, restarts and stops it when needed.
See the following links for tutorials:
How do I run a Play Framework 2.0 application as a Windows service?
http://marcovanduijn.blogspot.nl/2011/08/run-play-framework-application-as.html
http://blog.fgribreau.com/2013/09/how-to-make-play-framework-2-work-with.html

Web framework with user-friendly desktop deployment?

I'm building a web app with Backbone.js (I'm not tied to Backbone yet though). I need a back-end framework only for persistence to a database via a RESTful API. However, I also need to able to deploy it as a 'desktop' app for off-line use, i.e. running a local server and launching a browser window, but I don't want users to have to start a server from the command line to run the application.
I can use SQLite as a database since it's only a single user application, it's just the framework that I'm stuck on. I have looked at the following:
Rails and Django: Default web servers are too flimsy, requires Ruby/Python and runs from the command line. I'm aware of the Bitnami stacks but at 99mb it's too big of a dependency and not exactly hidden from the user.
Sproutcore: Run from command line, also too bulky.
Pyjamas Desktop - Depends on MSHTML which I suspect limits my ability to use HTML5 features.
I'm leaning towards creating a Java app that starts a Scala/Lift server instance and opens a web browser, then sits in the system tray (kind of like WAMP). Is anyone familiar with a tool or framework built for user-friendly deployment as a standalone desktop app?
I do not know if PHP is an option for you? Then I would recommend phpdock.
web2py has a standalone deploy-to-desktop feature with no dependency on Python: http://web2py.com/books/default/chapter/29/14#How-to-distribute-your-applications-as-binaries
As Eydun said, phpdock is an option but it's commercially licensed .
I settled on using Java/Spring/H2/Hibernate/Jetty. I find that Jetty serves requests VERY quickly so the application looks real-time when launched in a browser. There is a tutorial on embedding the Jetty server here. I imagine it's quite trivial to build a GUI that launches the server and a browser.
Another Java option is to use the Play Framework, which may be more at home to those coming from a Django/Rails background. However, the documentation for "creating a standalone version of your application" for Play 2.0+ indicates that they have ditched using Java EE containers (Tomcat/Jetty) and WAR files in favor of running the JARs with the bundled copy of JBoss Netty, so it may take a bit of work to get it running the way you want it.
I would recommend the Play Framework approach if you're OK with using/learning Scala.

Spring batch application integration with spring batch admin

I developed one spring batch application which is deployed as executable jar using batch/shell script. It works fine.
Now recently I read about spring batch admin application release. As per their doc, they say you have to point to job-context.xml and that will allow to manage spring batch app to be started,restarted and stopped from admin app. Now my question is do I have to keep my job-context.xml outside the jar or what are the exact steps, i am confused about this configuration.
Any insight on this is very useful and by the way I am using spring batch 2.1.
Thanks
The Spring Batch admin application is a good reference implementation and is highly customizable. All interface implementations may be replaced via Spring DI using your own classes. UI is also template driven(FreeMarker I think) and therefore may be customized to display relevant information, change skin etc.
I had a similar need like yours - need admin functionality included in an app built as jar. I did not quite like the fact that I had to package my jobs as a .war file. Instead I extracted relevant configurations from Spring Batch Admin source and created a deployment that works off file system and runs on embedded Jetty server.
See screen shots here : https://github.com/regunathb/Trooper/wiki/Trooper-Batch-Web-Console
Source, configurations etc are available here : https://github.com/regunathb/Trooper/tree/master/batch-core . This project actually creates a .jar and not .war
If your application has custom classes and is deployed as a runnable jar and not contained within the spring batch admin, you cannot start jobs. You can only view the status of jobs and "kill" their status in the database.
If you look at http://static.springsource.org/spring-batch-admin/reference/reference.xhtml at the end of the Configuration Upload section it states
You can see a new entry in the job registry ("test-job") which is
launchable in-process because the application has a reference to the
Job. (Jobs which are not launchable were executed out of process, but
used the same database for its JobRepository, so they show up with
their executions in the UI.)
If your jobs are strictly configurable jobs, as-in you use only XML to define them and do not need to do any customized item readers/processors/writers or other custom classes, then you can upload the job XML and it will be runnable from within the admin site. If you have custom classes then, from my experience, you will have to have the spring batch application deployed within your web application and then upload an XML that contains the jobs you want to run separately.
I personally just used the Admin tool to view job status and provide me with statistics through some custom pages. I left the scheduler to run the jobs and I didn't want those with access to the admin site to kick off a job when they knew nothing about it. Basically, used it to give the users a warm fuzzy without allowing them to muck it up. (leave it to a user to find an edge case you didn't account for)