Gradle jettyRun set webappsourcedirectory with DropWizard - java

So I'm developing a DropWizard application and all of the tutorials point towards compiling and running java -jar to start the web server. However while I'm doing local development this is a pretty slow work flow. Having used Jetty before I know it will autoreload and run in a daemon mode.
We're using Gradle and I found this which works to start Jetty. The first problem I encountered is this:
Directory '/src/main/webapp' specified for property 'webAppSourceDirectory' does not exist.
I found I way around this by adding
jettyRun.webAppSourceDirectory = file("src/main/java")
to the build.gradle file but of course this just lists files in that directory. Is there a directory I can point jetty to for this to work?
Or is there another way I can get DropWizard to auto reload resources and recompile?
Also Is there a way to get DropWizard to run in the background?

Dropwizard doesn't run on Jetty. It manages Jetty, as well as other tools. So manipulating jetty is not a solution for what you want to accomplish.
Or is there another way I can get DropWizard to auto reload resources
and recompile?
No AFAIK.
Also Is there a way to get DropWizard to run in the background?
Also no AFAIK. You should be able to fix that with some bash tricks.
Or maybe this might be of some help, but I don't think it will recompile and reload resources.
Dropwizard is a fairly lightweight application. In my development environment it takes about 3-5 seconds to build and start a dropwizard service; that is by using Intellij, not gradle (or maven).

Related

How to create a Spring web app on a server

Firstly, please excuse my horrendously general question, as my understanding of Spring is very limited, but I will expalin what I want to achieve, and hopefully someone can point me in the right direction.
I have an application that retrieves some information from some source and updates a database. I'd like to put this program on a Tomcat server, so that the application is run every day.
I'm very new to Spring, and have spent the last few days completing some basic tutorials to display Hello World! in a broswer.
However, all of the tutorials I have found relate to Controllers for URLs, which, as far as I understand, is not what I want, as my application will not have a URL and there will be nothing to display, I just want the application to "hidden" somewhere on the server, and to execute daily.
I know this is a very general question, and as I said my knowledge of Spring is next to non-existent, so I'd appreciate it if someone could point me in the right direction, I'll happily do research if I just knew what to look for.
Thanks in advance!
I would suggest using Spring Boot quite easy to start with and does all the magic for you.
There are few tutorials how to start and what you will need.
You can have a jar that will run on embedded Tomcat server provided by spring boot, or you can convert it then to a war/ear file and deploy it on External Tomcat if you wish (doesn't need to be tomcat either). You just need a deployable artefact. In this case a war or ear.
Difrence between jar, war, ear
if you then wish to convert it:
Convert a jar into a war
Deploying Spring boot apps on External servers
All the documentation you can find on Spring guides
I'd like to put this program on a Tomcat server, so that the application is run every day.
Seems to me that you don't really need Tomcat or Spring.
Why not just install your Java app on a UNIX server and have it run every day with cron ?
Spring is a very frustrating framework to learn because of all the various versions and tools out there.
Spring Boot is usually the starting point for people since it creates an executable self-contained JAR with embeded Tomcat server.
If you want to run with your own Tomcat instance, you need to look into creating a WAR/EAR file, which is an archive with a directory named WEB-INF that contains all of your Tomcat XML configurations.
Turn your Jar into a War
One of the simplest ways to start is to use Maven, add the WAR plugin to your pom.xml file, then webapp/WEB-INF directory to your project and place the web.xml config file in it.
Create and deploy web apps on Tomcat

Spring boot can not find jsp views

Helo everyone!
I completed my Spring based web app and then started to rebuild it to Spring boot because it gives me ability to use embedded jetty.
At the moment I got some problem - Spring boot can not find (resolve) jsp views. So when I run my app - I get the error in browser:
Here is my web app on github - so you can just look at files and find the reason.
Help me please!
P.S. Yes I used #ResourceImport because I don't know how to rewrite the existing spring configuration xml files to java-based config files but you may show me HOW to do that in your answer.
P.P.S. And for some reason the target directory does not contain WEB-INF and it's content folders after compiling. May be this is the reason but I don,t know how to solve it!
I checkout-ed your code from github and managed to deploy into embedded Tomcat 8.0.3 and standalone Tomcat 8.0.x.
I will just go through the steps for embedded Tomcat instead of Jetty(as I have not figured out the Jetty configuration fully yet).
There are two things that you could do
Copy your webapps into the following location without the s, e.g. /dvdexchange-spring-boot/src/main/webapp
Modify slightly your pom.xml, e.g. below
The final outcome as below
-
UPDATE:
IngeniousTom,
I was not able to make it work in embedded Jetty, the furthest point I could reach after struggling to add numerous Maven Jetty jar libraries as shown below
This is actually a known issue and I do not see how this can be solved without any hackish way.
If you read in the github link, there is numerous discussion between Spring-Boot and Jetty camps.
The bottom line of the discussion is that Spring-Boot does not support yet Jsp in embedded Jetty as their standard but have plans in future.
My recommendation is not to use Jsp or use other than Jetty as your embedded container.
JSPs in executable JARs are not officially supported by Spring Boot, this is one of the known JSP limitations. Also, Spring Boot supports JSPs in embedded Jetty as of 1.4.0.RC1, not before.
Right now you can solve this by using Spring Boot 1.4+ and packaging your application as an executable WAR. You'll be able to deploy your app as a regular WAR, run it with java -jar app.war and have a nice development experience - all of this with standard JSPs.
Maybe you'll find tricks to work around those limitations, but keep in mind that those often rely on container-specific behavior that aren't supported by the servlet spec. So at best, this behavior will be inconsistent between containers - and it's certainly possible that containers may change their behavior at any time.
If you really want to package your app as an executable JAR, then the best approach is not to use JSPs and pick a proper template engine.
If you want to do a jar-Deployment you cannot use the wepapp folder.
Put your JSPs to src/main/resources/META-INF/resources/jsp
Put these lines to your application.properties file:
spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
You can have a look to this project. It also uses Spring-Boot, a jar-Deployment and JSPs: https://github.com/synyx/urlaubsverwaltung

Dropwizard hot deployment

I'm looking for a simple to use system in Java which creates a REST service for me. So I found dropwizard but as far as I can use google it turns out it lacks hot deployment although jetty is able to do so. When using the maven-shade-plugin it takes at least 10 seconds to build the thing. Also my IDE reports that it cannot use compile on save feature (aka hot deployment) when the shade-plugin is involved.
Can I use hotdeployment somehow? Or what can I use instead?
Update: If nothing will fix this I'll probably use a combination of jersey&guice etc which is explained in this post
You don't have to use the shade plugin to run your service. You could just compile as a regular jar file and I think that would let you use your IDEs hot deployment features.
Have you ever tried JRebel ? They have JAX-RS support as well...
Not an answer, but I wrote up an article detailing how to use git to push a Dropwizard project to your server and for it to initiate a hot replacement. It relies on git hooks and running Maven via a script on the server.
You can find the details about it here: http://gary-rowe.com/agilestack/2013/02/14/how-to-deploy-dynamic-sites-with-git/

What's the simplest way to deploy a Grails-generated WAR file?

I've been having persistent problems (for several weeks) getting Tomcat to deploy a WAR file. I'm looking for a simple server. It does not need to have a lot of functionality-it just needs to be simple to set up. In particular I'm looking for a program that I can just drop a WAR file into and have the enclosed web application launch.
You might want to give jetty runner a try. It basically just uses an embedded jetty instance to run your war file.
http://blogs.webtide.com/janb/entry/jetty_runner
It is available on Maven and it is in fact how heroku apps built with grails are ran. http://devcenter.heroku.com/articles/deploy-a-java-web-application-that-launches-with-jetty-runner
If your application does not start on tomcat, it almost certainly means it won't start on any servlet container - containers implement a spec, and are very similar in many aspects.
What you should do is go and hunt each problem one by one, until the application starts. The problem is the app, not the container.
I recently had a similar problem where my app ran fine with "grails run-app" but not as a war file. It was caused by a missing "package" line in one of the files. I was getting 404 errors. When a war file is unpacked on the server it doesn't put files in the same directory locations as when the are in the grails environment. Not sure this will help you but maybe others with similar problems.
if you get a fresh tomcat instance, generate a hellow world app and generate your war file via grails dev war it should work without a hitch. typically problems arise form adding dependencies that clash with server libs.
if you want to give other servers a try I would suggest resin as one of the easiest to setup, run and maintain.

Questions about developing GAE apps on Eclipse with Clojure

After getting counterclockwise working on my Eclipse setup
and GAE development server running in interactive mode I found these
things still unclear for me:
1) How can I start server and application without commanding it on
REPL?
2) When I deploy application to Google servers, how and where do I
define the entry point of application? I mean, how Google will know
which application, application handlers and routes to use?
3) Can I combine using java classes and clojure files on same project
so that both are compiled automatic when creating and editing them on
my src folder?
4) Which files and jars are actually needed for uploading to GAE at
the end? Im used to deploy PHP apps to GAE, but here I dont know if I should make jars, include compiled clj files. I also might like to organize files different way than counterclockwise or appengine-magic does, so where do I specify paths to resources and classes?
5) Finally is it possible to connect Google production server with
Emacs - Slime - Swank combination? That would be the fulfill of
dreams, lol.
I'm using appengine-magic with Jetty, Compojure, Ring and Hiccup.
I'm going to suggest a lein/appengine-magic/Eclipse hybrid approach. Create your GAE project with appengine-magic and then set it up in Eclipse.
Create a Clojure "Run Configuration" and check the source files you need evaluated to bring the server up. You will get a REPL to it when it starts.
Your GAE entry point is your web.xml server-class, which refers to the ahead-of-time compiled source in app_servlet.clj (assuming you used lein appengine-new to create the project originally). Look in app_servlet.clj for the call to make-servlet-service-method -- the argument there is your App Engine Magic (see def-appengine-app in core.clj) entry point. In turn that refers to your Compojure handler and routes. See https://github.com/gcv/appengine-magic for the details.
I have not done this, so cannot comment.
Let appengine-magic take care of this: lein appengine-magic prepare, then deploy the deploy the war directory appcfg.sh (which you can find in the GAE Java SDK). You may also be able to use the GAE Eclipse plugins to achieve this.
You cannot use sockets with GAE. Swank depends on sockets, so a REPL to your live application is not possible. You can REPL all you like with the dev server however.
Q 1 & 2 were eventually solved and cleared.
Q 3 I wasnt able to do it because either java or clojure classes overwrote each other and I couldnt change target directories for them separately.
Q 4 after first succesfull deployment now I know what are the core base jars to be included. Yes it depends on what you happen to use on your project. I think I have transferred way too many unnecessary files on PHP deployments.
Q 5 Thats what I thought. But I didnt get swank working on dev app engine server. Its reporting illegal access to some appengine sdk file. Maybe I need to include it on project libs...

Categories