How to deploy Play! framework app to Openshift v3 - java

Perhaps I pop this question to early as Openshift v3 is still in preview, nevertheless there might be a solution to my problem that I don't see :).
I'm taking my first steps in building a java Play framework app and chose Openshift as my hosting platform. I just was able to get my app + mysql db working on Openshift v2 as they released v3 preview and got notice v2 will eventually disappear.
In the new images/templates there is still no Java Play version showing and no 'do it yourself cartridge' way.
Any hints or 'tutorial' links are much appreciated :).
Thanks and kind regards!
Erik

You have two options here.
SBT Native Packager
First option would be using the SBT Native Packager SBT builder to create your Docker images (either manually or using something like Jenkins). Out of the box you should be able to run sbt docker:publishLocal and get a local docker image which you can then push to a Docker repo. You can then launch it in openshift with oc new-app <docker repo>/<docker image>:<image version>.
Down side to this is that you aren't really taking advantage of OpenShift fully since your images are being built elsewhere. But it might fit well with your current development flow.
Upside is that your docker images will be quite small. SBT does a good job of packaging up all the dependencies.
Source to Image
Second option would be to create your own source to image builder that knows how to build sbt/play projects. This is the path my team has taken. You can take a look at our sbt builder for reference but its still beta quality at best.
Downside to this process is that all your source is included in the image so its a big larger. Also no one supports this builder so if you have bugs you are on your own.
Upside is that OpenShift will build your images and you will see your build status inside the OpenShift web console.
Notes
With OpenShift Origin 1.3.0 you will also get access to the Jenkins pipeline. This can make either of the two above scenarios easier. You end up with a cool web interface that looks like this:
Hopefully RedHat will support sbt natively at some point but for now one of these two flows should work for you.

For everyone looking for an answer to my own question, here is how I got a Play app running on Openshift (own installation).
First of all, a big thank you #PatrickTescher. His answer pointed me in the right direction.
I did not yet succeed in getting a docker build by activator to work in Openshift (guessing it has to do with running under root), but I have gotten to the point where I have a Source to Image build running on my own Openshift Cluster. This approach is not yet possible with the online developer preview of Openshift. By all the reading I have done so far, I agree with Patrick to say this is the best approach.
By diving into the following links, you should get up and running:
Installing docker on a Windows vm: https://docs.docker.com/toolbox/overview/
Installing your own Openshift Cluster: https://github.com/openshift/origin/blob/master/docs/cluster_up_down.md#windows-with-docker-toolbox (in addition: https://github.com/openshift/origin/issues/11277)
Get a s2i image up and running: https://github.com/redhat-cop/containers-quickstarts/tree/master/s2i-play
In the last link you can change registry.access.redhat.com/rhel7.2 by registry.centos.org/centos/centos:latest (rhel needs certification, centos is the free community equivalent)

Related

Eclipse Neon running GAE is incredibly slow to refresh

I have just deployed Eclipse Neon in a Windows 7 environment (coming from many years of using Netbeans) and the Google (java) App Engine environment (as Google instructs and all works).
Using the standard gae 'hello world' example, when I make a change to the text on the sample 'Hello App Engine Standard' .jsp, for example changing that text to 'Hello hello', I have two issues:
In Eclipse I have to save and then hit F5 to refresh. Is there any way that Eclipse can auto-refresh on save like Netbeans does?
After saving and hitting F5 I then need to reload my browser 4-5 times before the trivial change shows up. Netbeans does it instantly. Does anyone have any idea where I start looking as Eclipse is totally new to me or is this just the way Eclipse works?
Thanks
If you are using the Cloud Tools for Eclipse plugin, you can set the publishing delay on the server as follows:
Double click on the local devappserver in the Servers view:
In the editor that opens up set the publishing interval to 0 seconds:
I had previously done some work in java GAE. Eclipse was pretty terrible frankly ended up switching to intellij. Shortly after I ended up switching to python for it. I use pycharm from the same company, you need the pro edition sadly, also here is a great lib for it supposedly it runs fairly similarly in terms of speed in GAE compared to java. Also endpoints will generate client code for you with little work.

installing play framework 2.4 on windows 7

some questions:
i unzipped the full offline distribution (400+ mb) to C:\Program Files\Play2.4
Unzipping created a directory "activator-dist-1.3.5" within which are bin, lib, repository, templates, etc.
i assume i put the contents of activator-dist-1.3.5 into C:\Program Files\Play2.4?
i setup an user environment variable name: PLAY_HOME, value: C:\Program Files\Play2.4 and then added ;%PLAY_HOME% to the end of the system variable "Path"
i've tried calling "play" from dos both with and without "activator-dist-1.3.5" directory and both return "play is not recognized as an internal or external command"
some other answers to this question mention the root play dir should have "play.bat" but all i see is "activator.bat"
i read readme.html and opened activator.bat, it launched a dos window, which promptly closed.
http://localhost:8888/home goes nowhere.
For those who don't yet speak "play", what is Activator UI?
Since play 2.3, the play command was replaced with the activator command. Take a look to this.
If you put the folder activator-dist-1.3.5 into C:\Program Files\Play2.4 then your enviroment variable must be set to C:\Program Files\Play2.4\activator-dist-1.3.5\bin. You can also put that path directly into the PATH environment variable.
Activator UI is a web aplication that helps you create play applications. You can think of it as the graphical version of the activator command line tool. Here is the documentation
ok, here is what ive figured out:
the environment variable has to point to the bin directory (thx Victor)
from w/in dos window (the "console"), cd to the the root play dir (not bin) and type "activator" not "play"
all other documentation and stackoverflow answers refer to the pre 2.3 versions of play and will not help you.
then a bunch of stuff happens: online maven call (even though i downloaded the offline dist) and a bunch of calls to the play root dir/repository for jars.
of course localhost:9000 and localhost:8888 still get connection refused.
now if you manually open activator.bat in root play dir it launches another dos window, makes a network call (firewall allow) and opens a browser win to: http://127.0.0.1:8888/home which is some sort of "welcome to activator" screen with sample apps .. sort of like the tomcat mngt page.
i hope to only define and start/stop apps from w/in my IDE, so eventually i'll be looking for how to disable this default activator behavior
next up.. how to setup intelliJ:
i went here: https://www.playframework.com/documentation/2.4.x/IDE and defined an SBt task instead of a play task in run/debug configurations of my new project.
now project start makes maven calls for jars but then dies on:
[error] Server access Error: Connection timed out: connect url=...repo.typesafe.com/typesafe/ivy-releases/org.apache/apache/14/jars/apache.jar
stopping and restarting did a bunch more maven calls (really slow) but eventually "done updating" and localhost:9000/ now shows welcome screen :)
not completely painless but certainly simpler than a spring app
onEdit:
sorry play, but i've moved to spring boot because:
i create new projects by copying existing and making changes. its much faster than creating a new proj from scratch. Thus the activator thing (which does not work) is not useful to me and just represents a security prob (like apache web management screen) that need be disabled
no where is there a clear, concise and complete list of settings to get play running correctly in intelliJ (the 2nd most popular IDE avail)
asynchronous, non-blocking and micro services are not unique to play and spring (or others) can be made to work in a similar fashion
We have so many technologies to learn and it does'nt make sense to invest a lot of time mastering one with limited corporate buy in
i want to stop/start from w/in my IDE and not have to have a bunch of dos windows open. i know this is possible in play, but documentation makes it feel as though its not the preferred method
although i appreciate that the play directory structure is less flexible, its still not the command/controller/manager/dao/model world that is the most often seen for java apps
i investigated play because spring was getting to the point of having too many ways to configure too many things in too many places that were documented differently across versions. Also, large sub-projects in spring (like security) garnered their own books on the subject because they were so complex to figure out. At the end of the day, the level of security (for example) needed (or the manner in was implemented) went beyond what avail via simple configuration and after all the customization we were left wondering whether spring security just got in the way instead of providing real time saving and usefulness.
Spring boot hopes to help in that its an opinionated configuration where a collection of configuration basic best practices are encouraged/enforced.
and lets re real.. time saving on a slightly more concise language or a slightly different proj structure or dynamic class loading is not whats important.
The majority of time spent on projects, by far, is the time spent researching, thinking and investigating architectures, technologies, databases and presentation schemes.
I prob only spend 20% of my time coding and 80% trying to figure out the strategic vision needed to create software that has maximum usefulness and is "future friendly" (not needing to be re-coded every 3 years)
so far i've deleted my project and recreated about 10 times.. trying diff settings, still w/ no luck.
checking google play mailing group, i tried to create via activator ui.. but could not launch activator until i deleted the RUNNING_PID file in the play root dir
now i'm back at: http://127.0.0.1:8888/home to create a new app
at create new proj i get error: "cannot find project/build.properties".
lets try adding a blank build.properties where its expected.. nope, error: "destination already has files in it"
not that it really matters, sample templates have no knowledge of IDE and thus provide no insight into how to configure IJ. New\Import project does not list IJ as an option in choosing an external model
...whatever...
"Mr McKitrick.. after careful consideration ..."
trying to get working in IJ 14 ultimate:
jamesward.com has a tutorial and video, but its for older versions of IJ and play and only covers a small % of necc. configurations.
jetbrains has a tutorial but it also only covers play 2 and older IJ which does not translate to 14 and 2.4
https://www.playframework.com/documentation/2.4.x/IDE helps, but just w/ setting up an SBT Task
all the other project settings are a mystery for example:
project source need be defined to even show your project directories in proj tree
facet setup add does not list scala as option
why is scala lib pointing to users[me].ivy2\cache..? (i would think all necc libs are w/in play root\lib
should i setup a global lib pointed to play\lib?
run/debug config need env var pointed to PLAY_HOME?
basically all classes are not being resolved in IJ editor.
project structure lists 109 problems like:
Library SBT: joda-time:joda-time:2.3:jar is not used [Fix]
seems like i'm missing a global lib definition.
i'm able to get my app running, but i dont know how useful its going to be when the 2nd most popular IDE throws red bars at every import: "play."

Eclipse subversive on dev box issue

I recently started on a new project where they do not have eclipse working with subversion. They say it is not possible because our dev boxes do not get internet connection. However, I'm not so quick to give up.
We are currently using TortoiseSVN over our secured network just fine. Surely we must be able to set-up Eclipse to do the same?
I have done some research and am having a hard time finding an answer off google searches and thought I'd ask here. Most of the SVN eclipse guides ive seen require a web address to host the file. Any thoughts?

install tomcat and java and run jsp in the browser

For quite a while I have worked in the LAMP stack. But now I need to work on a project in java ,jsp and servlets(Tomcat Server) I have never worked in java ,jsp before. So I need some help in setting up the stuff in my laptop so that i can execute a java and jsp script in my browser. I know there are numerous links in the web that provide tutorials. But could someone point me to good one where it shows all the steps:for eg:
Installing Tomcat
Installing java
compiling,build,test java,jsp,servlets in the browser
Or anything else that would help me get started and learn the right way to develop web applications
I think this tutorial from Lars Vogel is a comprehensive one and is quite up-to-date.
The only point not covered is "installing java", that should be your first step. This article can help you in getting used to JDK, JRE, JVM, etc.

Java web development using Eclipse - Tutorial

I need some step by step tutorials/documents on developing Java web applications using Eclipse/apache.
appreciate directions/help.
I recommend you read a book instead:
This is probably the simplest way to get started. It really helped me with getting a grasp on how the directory structure and web.xml go together and make a web app. Eclipse is only a partner in your development, you really need to understand the underlying infrastructure no matter what framework you are using, and this book gives you a solid start.
There are some video tutorials available at http://eclipsetutorial.sourceforge.net/
The first tutorial begins with the absolute basics of setting up a workspace and getting started. It also shows the Welcome screen available under the help menu which has links to an overview, samples, and tutorials
As you've already installed Apache Tomcat. I assume you've not installed Java EE tools for Eclipse. If not, then First download Eclipse Java EE tools from Help > Software Updates > Available Software > Java EE developer Tools.
First way : is using Tomcat plugin with eclipse,for that you've to check this tutorial
Second way: If the Tomcat Plugin is not working with you then other alternative as follow Click on Click Window in menu> Preferences then click Server pane. Open Runtime Requirement pane. Add path for the tomcat directory. Click Ok. You're done with the settings.
Now you can create new projects from File >New >Projects. And start building servlets/jsp projects. Try learning from good books like "Head first: Servlets & JSP".
Hope this helps.
When you first start Eclipse there is a screen with tutorials right in the program. They are also accessible from the Help menu
Reminds me of that old joke:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
Sounds like you have several things that you don't know: Eclipse, Tomcat, Java EE development, maybe JSPs, JSTL, WAR files, the list goes on.
My advice would be to strip things down to the bare bones and decompose the problem a bit.
Start by doing a simple servlet/JSP app talking to a database, without using Eclipse. See if you can compile on the command line, create the WAR file, package it properly, and deploy it on Tomcat.
If you can manage that, then work Eclipse into the mix. Don't worry about running Tomcat inside Eclipse at first. You can go back and forth until the IDE is comfortable.
But you're asking a lot when you say you'd like step by step instructions. You're tackling a very big problem.
DZone REFCARZ might be helpful, there's one for eclipse:
Getting Started with Eclipse

Categories

Resources