Tapestry webapp with embedded Jetty - jetty

How can I configure a Tapestry5 project to run standalone (via java -jar) with embedded Jetty?
I'm looking for a short "recipe" regarding Tapestry5, Jetty, configuration of servlets/ handlers/ whatever is needed to connect the dots...
I've seen a few dots: How to Create an Executable War, Configuring Tapestry (ref Tapestry as servlet filter)
Edit: I'm thinking about a standalone running webapp due to server circumstances. It doesn't have to be embedded Jetty, but I can't rely on a stable appserver. Still looking for a recipe, though, so I don't spend much time on dead ends...
Also, I'd like for Jenkins (Hudson) to be able to stop and start the server automatically when deploying updates - I don't know if that influences what I can do with Jetty, f.ex.

Well, i believe this is a general "how to run a war question". Assuming you indeed have a war, you can use jetty or winstone to "run" it - see :
http://winstone.sourceforge.net
and
http://www.enavigo.com/2008/08/29/deploying-a-web-application-to-jetty/
In the first case, you can directly do
java -jar winstone.jar --warfile=<warfile>

https://github.com/ccordenier/tapestry5-hotel-booking/
<-- Check its maven build
http://tapestry.zones.apache.org:8180/tapestry5-hotel-booking/signin

I did some digging, and this is the short recipe I basically ended up following:
Start with the Maven Jetty plugin as configured in the pom.xml of the Tapestry 5 archetype
Add the stopKey and stopPort attribute to Maven Jetty plugin configuration
Let Jenkins CI run maven target jetty:stop and then clean install
Let Jenkins run shell script mvn jetty:run &
Voila - my Java app is up and running with automatically updated code, without any appserver.

Related

Use Leiningen to build frontend with Gulp

I have a pretty standard Ring application with some Compojure RESTfull endpoints. We also have a frontend application based on Polymer, Bower and Gulp. So I thought it would be nice to distribute this application in one package (which means having a build which will in the end produce a WAR file consisting of both backend and frontend part which can be uploaded anywhere without any other dependencies).
However I started to dig into the Leiningen and apparently there is no plugin which would support this need. So before I am gonna build something like that on my own, is there some other way how to do this? Or am I thinking about the problem in the wrong way?
P.S. The ultimate goal is to deploy application to AWS, I've done it already via elastic-beanstalk plugin and it seemd to me pretty smooth (just build the WAR, pass it to the plugin and it will take care about the rest).
I have built projects with similarities. I avoided using leiningen/lein-plugins to build the frontend and instead built it with webpack, while letting lein compile the clojure into an uberjar. The build artifacts from webpack were output to the resources path that was declared in project.clj and packaged into an uberjar. The web server was also bundled in the uberjar and was configured to serve from that path. I used luminus as a project template.
It seems like you could do something similar here. Use gulp to build the frontend and package into a war that can be deployed to elastic beanstalk. My build script from package.json was this: npm install && NODE_ENV=production webpack -p && lein uberjar.
So, you don't need to have a lein plugin to build your frontend. I found it easier to let another build tool do that work.

Developing in Adobe CQ5 with jetty?

We use maven to deploy the code changes to cq interner server / CRX Lite and the problem here is that it takes long time where the changes itself is often only one line code.
Has somebody experience with CQ5 with jetty and can give me a good Guide?
am not sure i understand the relationship with jetty (which ships as servlet container of latter versions of AEM/CQ5), but will answer to the code deployment part:
deploying a full content package (full content) should be done using
maven-content-package plugin for smaller deployments of content,
when you can't use integrated dev environments like sling eclipse dev
tools, i'd suggest you use the excellent repo command that basically zips the current folder and deploy it. I'm using it as an external tool command of intellij and it's really fast.
finally, if the deployment you're referring to is osgi deployment, maven sling plugin can help you with that (will still compile/package the whole osgi bundle though)

How to stop jetty runner from executing

Am using jettyrunner for executing my war files.I am using command java -jar jetty runner ex.war.But am running this jetty server from my java application by executing this commands from java.My problem is at first time its working good,but the second time if i am again executing another war file with the same code its executing the older war.i have found the reason that the older jetty server is keep on running.How could i stop this server from java in order to start the jetty server for another war.
One option should be:
http://wiki.eclipse.org/Jetty/Howto/Secure_Termination
Another would be to use the ShutdownHandler:
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ShutdownHandler.java
Or don't use the jetty-runner directly like that from java code and just write a small embedded usage:
http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
Turned out, jetty-runner.jar doesn't have a feature to stop existing jetty process ran with stop-port and stop-key.
I found the answer in https://github.com/jetty-project/jetty-documentation/blob/master/src/docbkx/administration/runner/jetty-runner.xml
Then, to stop jetty from a different terminal, you need to
supply the same port and key information. For this you'll either
need a local installation of jetty, the jetty-maven-plugin jetty-ant plugin, or write a custom class
Fortunately, I was implementing gradle build, so jetty-ant satisfied my needs.

best way to deploy jetty application--too many options?

I need to deploy a production version of a web application. So far, I've been testing it with mvn jetty:run. I've used actual jetty installations before, but they seem only necessary when you want to serve multiple wars on the same web server. In some ways this is the most staightforward however (mvn package and copy it over).
My other options are to create a runnable jar (mvn assembly:single) that starts a server, but I need to tweak the configuration so that the static content src/main/webapp is served and the web.xml can be found.
I've also read about a "runnable war". This might avoid the src/main/webapp problem since these files are already laid out in the warfile. I don't know how to go about doing this, however.
I could also stick with mvn jetty:run, but this doesn't seem like the best option because then the production deployment is tied to code instead of being a standalone jar.
Any opinions on the best way or pros and cons of these different approaches? Am I missing some options?
The jetty-console-maven-plugin from simplericity is simple to use and works great. When you run mvn package you get two wars--one that is executable. java -jar mywar.war --help gives usage, which allows a bit of configuration (port, etc.).
I'm not that familiar with maven, but this is how we approach deployment using embedded Jetty:
We create a single-file JAR with the embedding jetty app and the necessary lib jars packed.
We deploy the static content in a WAR file (which you can package into the JAR as well). Everything is generated by an ANT file that:
1) Build the static files WAR (this also creates the web.xml)
2) Copies the WAR into the application resources
3) Compiles an executable JAR
To get the embedded Jetty to "find and serve" your static files, add the war with a WebAppContext to the Jetty handlers:
Server jetty = new Server(port);
HandlerList handlers = new HandlerList();
WebAppContext staticContentAsWar = new WebAppContext();
staticContentAsWar.setContextPath("/static/");
staticContentAsWar.setWar(resource_Path_to_WAR);
handlers.addHandler(set);
jetty.setHandlers(handlers);
jetty.start();
HTH

how to run metro webservice on jetty in Maven project?

how to run metro webservice on jetty in Maven project??
As per this source.
If you place your web service in a WAR file, like here, it should run fine
on Jetty, just as it would on any servlet container. There might be some
subsequent Jetty-specific configuration needed, but I would try to deploy
the WAR first on Jetty and see where it gets you.
If you want to embed Jetty, instead of running on Jetty standalone, this
might give you some pointers.