How to switch from jetty:run-war to jetty:run? - deployment

I have a multimodule maven application running on jetty, I would like to use jetty:run to speed up development + make available to hot introduce hot deployment. I've used this tutorial:
https://gist.github.com/naaman/1053217
but I had to use <webAppSourceDirectory> parameter to point onto the extracted war directory. Thing is that I can't compile the code, to see if the hot deployment works. Maven is saying that some resource is in use, so it can't be replaced. I'm working on IntelliJ IDE. Is there any way to have both jetty:run and hot deploment working with together? Any ideas are welcomed

Related

Is Hot-Deploy of JSP files with Jetty Maven Plugin (from within Eclipse) using Maven's WAR-Overlays possible without restarting Jetty?

Hello I'm using the maven-jetty-plugin (v 9.4.7.v20170914) from within Eclipse (mvn jetty:run) and changes to JSP files where reflected immediately without the necessity of restarting Jetty (scanIntervalSeconds=0) before I was using the Maven WAR-Overlay feature.
After changigng the project to a Multimodule layout and using Mavens WAR-Overlay feature changes in JSP-Files are only reflected when restarting Jetty.
My question is: Is it possible in general to immediately reflect JSP-Changes using the Jetty-Maven-Plugin and Maven WAR-Overlays without the need of restarting Jetty?
I'm looking around for a few hours now and tried loads of things. I'm not sure if I should spend more time investigating this issue if it is simply not possible...
Sure, you can use mvnDebug jetty:run to run you app, as this is in debug mode, so you can compile your jsp file( as eclipse will automatic compile your file so you just need save it )
and suggest you to use the dcevm plugin for hotswapping.

best way to enable hot deployment on Jetty when using Gradle+Eclipse

I'm used to mvn, but I'm testing Gradle (v1.8) for a small web development project.
I've noticed that the Jetty Gradle plugin support autoscan and hot deployment, so I've enabled it. My goal is to recompile from Eclipse and get a Jetty reload the context every time I change a Controller, etc.
However, this is non working, mainly because Gradle compilation output goes to build/, however the Gradle Eclipse plugin creates a .classpath configuration that directs all the Eclipse output to /bin (even mixing test and main source folders).
Is there a way to?...
Run graddle jettyRun on a separate console.
Save a modified class on Eclipse (triggering a compilation)
See that Jetty picks up the change and reloads the context.
As per my research, I've identified three workarounds, but none of them solves the question above (I'm posting them in case you have related comments or more recommendations)
Tweak Gradle Eclipse config to direct test and main build output to the same directory that Gradle uses (using the pattern seen here). This is not recommended by some people, as it means using two different compilation systems that could interfere with each other.
Use the Gradle eclipse-wtp plugin to generate a WTP2 config, and use Eclipse's "Run AS -> Run on Server". This accomplishes the hot deployment / iterative goal and keeps both systems (IDE and Gradle) isolated. However, you need to setup the server on Eclipse.
(Not really a workaround): I've tested Spring's Eclipse build (STS) Gradle integration, however it seems that the integration is focused on the project setup, and while Gradle builds can be automatically triggered, Eclipse compilation is still redirected to bin/.
So you are interested in fine-tuning hot-deployment, right?
Please, consider using Gretty gradle plugin: https://github.com/akhikhl/gretty
It is an advanced gradle plugin for running web-apps on jetty. It does exactly what you want, regarding hot-deployment (and, possibly, even more).
Disclosure: I am author of Gretty plugin.
If you don't want to change to other plugins, here are two steps for the workaround:
add below configurations into your build.gradle:
jettyRun {
reload = "automatic"
scanIntervalSeconds = 1
}
each time after you changed java code, run the following task:
gradle compileJava
Because jetty is watching the *.class files, it will hot reload only after *.class files changed.
Refer to this link: https://discuss.gradle.org/t/hot-deploy-with-jetty-plugins-jettyrun/7416

How to configure the web container to run continuously so it will perform a hot redeploy using GRADLE jetty?

According to gradle.org :
Once started, the web container can be configured to run continuously,
scanning for changes in the project and automatically performing a hot
redeploy when necessary.
Searching around I can find a lot related to maven but the project I am working on uses gradle. I have the gradle jetty plugin installed but can not work out how to set it to hot redeploy when I have made changes to a html+thymeleaf file.
This should work:
apply plugin: "jetty"
jettyRun {
scanIntervalSeconds = 10
}
The scanIntervalSeconds and reload properties are inadvertently not listed on the JettyRun page of the Gradle Build Language Reference (fixed for Gradle 1.7), but the page links to the Groovydoc ("API Documentation" on the top), where you can find them on the superclass.
So, I've been looking for a way to hot deploy for a few days using the jetty plugin for gradle. I had no luck whatsoever with:
reload = "automatic"
scanIntervalSeconds = 1.
Jetty checks the build for any changes, whereas the changes that take place are in src. Changing jetty to watch the src folder seemed messy to me.
Instead I used the tomcat plugin for gradle.
Just follow the usage section on https://github.com/bmuschko/gradle-tomcat-plugin
Hot deployment is already configured in the plugin so just making the requisite changes to build.gradle did the trick. Hot deployment with gradle works for me now... a HUGE timesaver :)
If anyone has been able to hot deploy using jetty with gradle please share the process... until then tomcat is the way to go

Efficient dev cycle with Maven, Tomcat/Glassfish, Archetype?

So far i've been using tomcat and glassfish to develop a testing webapp, without maven. And the usual development-till-deploy cycle is simple :
develop in eclipse ide, with a WebContent folder, which is the root webapp folder that has the WEB-INF, web.xml, WEB-INF/lib, n all. The compiled classes location in eclipse is set to WEB-INF/classes.
after coding, i could just click on the reload button in glassfish admin console for that specific webapp. In tomcat, i believe it's reload also in the tomcat manager.
i could access the web application in the browser
Now if i would like to create a new webapp, that'll make use of latest stuffs of jsf, spring, jpa, hibernate, postgresql :
what recommendation of archetype should i use in the creation of the project ?
can i still use my previous steps of development? because i think it's very easy without having to repackage everything into a war file, or copying it into the tomcat's webapp folder everytime i want to test. Saving the files in eclipse, hit on the reload in the admin console / tomcat manager, and i could instantly test the updated webapp.
Or what do you usually do in the webapp development cycle ? Please share your experiences, =)
Thank you !
Development Cycle with Maven and Friends
Use Maven to drive your code-build-test-deploy-release cycle.
Start with Maven Archetype that suits closest to your web-app. This will create the whole folder structure for you and will add Jar depencies.
Use an embeded light-weight server like Jetty, this will be very fast on dev machine without sucking resources and is highly configurable. Plus, you can set it to auto-reload changes.
Most of Maven project are supposed to be test-driven. Of which Maven takes care of using it's surefire plug-in. So, every build will have a test phase.
You can define multiple profile for various environments (test, dev, prod, Win, Unix..). These profile will alter the behaviour of the project to be compatible with the environment.
Use Cargo, again a Maven plugin to deploy your builds on test or production server, which can be Glassfish, Tomcat, Jetty or any oter webserver.
Use Liquibase with or without Maven :) to manage your database changes the same way you manage your code change.
I came from almost similar project as yours in my previous company. Development with Maven makes things so smooth and the change is appreciable.
A little Google search shows that someone has worked on archetypes for JSF and JPA with Spring
Edit#1 -- added more details
Feasibility and Ease of Use
Maven is born out of neccessity to simplify the dev process for large and distributed code.
Maven is very well integrated with Eclipse -- so it's painless.
Jetty keeps monitoring source folders, so your changes gets deployed almost immediately.
You can customize the build to skip tests, to not build dependecies. When you just edit a UI component, Jetty will silently copy it to "target" folder.
If you're worried about copying and redeploying. You must read THIS to see how efficiently things are done, keeping in mind that you don't have to compile-test-deploy everytime you change a JSP or HTML.
That said, I would like to mention that Maven might be a challanging learning. This is an object oriented way of development cycle, to say. Most of us, who are used to build script, can find a bit tedious/verbose initially.
Resources
I would suggest to go through the following resources
Maven Book - Maven basics
Automated Deployment with Maven - going the whole nine yards If you can, literally follow this pattern.
Maven 2 Effective Implementation -- this book really helped us a lot.
for the q2 :
You can still run/debug app with tomcat from within the IDE (eclipse) even if you change the directory structure. (like the maven dir structure instead of eclipse's dynamic web dir structure)
Project properties - >
project facets - >
Dynamic Web Module ->
Click the appearing "further configuration available"
and set your content dir and context root.
You dont have to package everytime you want to run/debug it.
Another option is using Jetty
And I am sure there are more options others will tell as well.

Java maven development slow

I am developing a war/java website that is built via maven.
Currently, I have to make changes... tell maven to build them... then deploy to Tomcat. This is around 40seconds. So every change I make, I have to wait >=40seconds to see the change.
This is becoming very frustrating, so I have tried to speed up the deployment. I deployed the site via maven with war:exploded. Now, I edit the files live in 'deployed' format. The problem being I will need to move these changes back to the source location for pushing into our source control.
So has anyone written a script to 'undeploy' changes on the server carefully pointing them back to where maven expects them to be, or found another way I can instantly see my changes in a web browser. Rebuilding from source everytime is not a fun solution.
Currently, I have to make changes... tell maven to build them... then deploy to Tomcat. This is around 40seconds. So every change I make, I have to wait >=40seconds to see the change.
This is just a wrong way to use Maven in my opinion.
Either use something light like jetty:run (and hook Eclipse remote debugger to enable hotswap), see Configuring Jetty, Maven, and Eclipse together with Hot Swap.
Or use Eclipse WTP and deploy your project on a Tomcat server inside Eclipse (your project can be recognized as a Dynamic Web project whether you're using m2eclipse or the Maven Eclipse plugin).
Have you tried JavaRebel?
http://www.zeroturnaround.com/jrebel/
Use hot-deployment.
Just configure tomcat-maven-plugin and try tomcat:redeploy.