I have a Spring Boot Gradle application with apply plugin: 'war'. I run the application on STS by right click > Run As > Spring Boot App. It runs fine. Now I make a change to the code and I want to redeploy (and better automatically). The only way I know now is to stop the server and run again. Is there any faster solution?
Spring-boot provide something called devtools which is a very neat feature.
Include this starter on your gradle build
compile("org.springframework.boot:spring-boot-devtools")
This will automatically restart whenever files on the classpath changes. So you don't have to manually stop and start server.
you can see more details here.
Related
I just moved from eclipse to IntelliJ.
I have a spring boot project, that runs perfectly in eclipse. but when I tried to run it on IntelliJ, I'm getting "Process finished with exit code 1"
I've tried all the next solutions:
https://stackoverflow.com/search?q=eclipse+intellij+spring+boot
but nothing workes. any advice?
spring boot config
It seems like your application is failing on startup, probably due to missing configuration.
Put your correct spring boot profile in "active profiles".
For example, this might be "dev" or "dev,integration-tests" or whatever :)
I was finally able to solve the problem by deleting the contents of the folder .m2\repository\org\apache\maven\plugins\maven-site-plugin.
and reimport maven projects.
I have an application built in Spring Tool Suite and using angular as well for frontend. I am building my maven and the deploying the war in Tomcat. While the Spring dev-tools work fine for any application when it is deployed form the tomcat container within STS but not when I put the war in external Tomcat. Is there any way to hotSwap the application other than blackboxing my javascript in Chrome. Can anyone list down the complete steps to follow. I'm a noob.
I have already put a dependency sping-devtools in maven. There are many answers related to that but none of them is working. It is a big project and takes 4 minutes to build and then I need to deploy it in tomcat which is a lot of burden.
Looks like you are looking to hot reload the static files. In IntelliJ, it's simple as saving your code changes and doing a Build Project CTRL + F9. It's even better if you install a Live Reload extension for your browser so that any changes made is refreshed automatically. There are also other similar options for compile & build automatically in IntelliJ as well other IDEs such as Eclipse.
According to the Spring Boot Devtools docs, devtools won't run in "production mode"; that is, if you execute your Spring Boot app with java -jar .., then it won't use devtools' built-in JVM magic. However, the Spring Boot starter docs only show you one way of running your Spring Boot application...via java -jar....
So first I'm wondering: How do I run my Spring Boot app in non-production mode? I know you can run your app with Spring Boot CLI (e.g. spring run), but is that the only way?
Also, the same devtools docs mention you can explicitly remove the devtools jar from your production binary by using some excludeDevtools option, but they never explain where/how to use this. Any examples/ideas here?
1) One example of running a Spring Boot app in non-production mode (i.e. not from the JAR) is from an IDE (most specifically Eclipse or IntelliJ), where you can launch the application from the main method, or using the Spring Boot launch support. This is the most practical use of Dev Tools as it allows to continuously watch the changes in your application without restarting.
2) excludeDevTools is an option of the Spring Boot Maven Plugin http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/repackage-mojo.html or the Gradle plugin - see http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-repackage-configuration.
So in your case it would be
bootRepackage {
mainClass = 'demo.Application'
excludeDevtools = true
}
To start with Spring boot and devtools made development easier. Spring boot uses embedded servlet container ( tomcat,undertow,jetty) with this you can have production ready code even in non-production environment.
Coming to your question how to run Spring-boot application in non-production environments, we can run application directly from Spring tool suite IDE by right click -> run as Spring boot if it is local environment.
If the build tool used is maven then from command prompt mvn boot:run , if it is gradle then gradle bootRun from root folder of project location in command prompt. If you are packing your application as uber jar then Java -jar .., also if your environment is Linux you can start as a process.
Regarding ignoring devtools in production environment, Spring boot intelligently ignore devtools jar if we specify Spring-boot-devtools as optional scope in dependencies of your build tool(maven, gradle) . In gradle Spring boot gradle plugin takes care of ignoring devtools for final deployed jar or war
Update ::
To debug a Spring Boot application run with Gradle, as seen at http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-remote-debug-gradle-run596
Add this to your build.gradle file:
applicationDefaultJvmArgs = [
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" ]
In IntelliJ Idea IDE or STS, setup a new Debug configuration and in the options select "Remote". The defaults should be fine, but pay attention to the port number and transport type ("socket"). Have fun!
I have a Rest API based on Spring boot, embedded with jetty. Normally I start it with java -Dloader.path=blablabla -jar blablabla.jar. I've configured a teamcity Build step to look for new check-ins to the git repo, pull and build (maven) the project, generate artifacts..
Further, I've added a Deploy step which has dependency on Build step (successful completion and artifact dependency).. Here, I use powershell to push the artifacts to the server on which i want the rest service to run.
A few questions:
1) Powershell - Is it the right way to publish files to the server from teamcity?
2) How do i get the teamcity to actually start my spring boot app? Some sort of a remote command execution?
Note: Both teamcity server and the app server are Windows.
Solved it myself:
1) Yes, powershell does the trick pretty neatly.
2) Got it to work with a combination of [WMICLASS] 's create() and Start-Process. Check my answer here.
Cheers!
How to run Maven as soon as my server boots?
Is it OK to have a script executed using cron once the server run? or is this a bad practice?
I am using Jetty and Resteasy and running them on Maven to start my webserver.
What is the best solution for when my server starts, Maven automatically starts?
The command is use is:
mvn jetty:run -e
EDIT:
I am using Amazon EC2 to launch an instance and I would like to have the maven build to run as soon as an instance is launched.
Maven builds and runs Resteasy, Jetty and a bunch of other dependencies that are stated in the pom.xml file.
You can use your OS specific init scripts approach. A very good answer for Ubuntu OS can be found here.
Usually, you use Maven as a build tool, not a deployment tool.
What are you trying to accomplish? If you just want to boot Jetty, it comes with its own init scripts which will start it on boot if you enable them.
Unless there is a convincing reason to use Maven for this, I would have your Maven build process create an "executable unit" such as an executable JAR, a WAR, etc. and then boot that at startup instead.