Hot reload with Spring MVC in VSCode? - java

Does anyone know of a way to hot reload a Spring MVC (not spring boot) application in VSCode? I'm using the Microsoft Java Extension Pack and Tomcat for Java extensions to compile and run them, but it seems that for every change I make I need to rebuild the .warfile and restart my server.
Personally, I think this is highly inefficient and tiresome. Does anyone know how to make this process automatic? I migrated from Intellij because apparently this isn't possible in the community version.
P.S.: To be more clear, I'm using Spring MVC but I intend to build a REST API with it, so I will not be using any .jsp files.

There's a feature request in github: Autorebuild option as eclipse, where the author ask the auto-rebuild feature including rebuild war packages.
The programmer still keeps the issue open and waits for users to vote it up then decides if this feature is needed, so you may upvote and comment there.

Related

Local development setup

I'm currently looking into what better ways there are for deploying/setting up webapps locally after code changes and database changes.
So far I've seen the following tools/ways come by, and attempted each of them:
ANT build target that compiles, makes a jar, a war file and deploys that to the tomcat folder
Gradle build in combination with the tomcat plugin, which already does a bit of a better job than option #1
Good ol' fashioned command line
Setup run configuration within Intellij to do the deployment for you
Write shell script and call this via command line (haven't tried this)
To be honest I'm not finding each of these the ideal solution. I find option #4 the easiest as it allows me to, via a short-cut, easily deploy my changes and continue. This has however not given me an option for database changes yet, probably just me that missed it.
My question is mainly what tools/ways are you guys using in order to achieve an easy and maintainable development environment? What considerations come with those?
Well, let me tell you what I do for local web app setup.
In your favorite IDE(eclipse in my case) i'll configure the application server plugin(tomcat or webpshere) from Eclipse marketplace.
This setup will help to auto publish code changes to the server whenever I make a change in the application. I use Maven build tool for the application packaging. However I'm not sure about the database side.
For the people that were wondering how I ended up doing and found the best to work for me.
I currently have configured my IntelliJ IDE in such a way that the tomcat instance is linked and can be properly controlled and deployed, including debug, from within IntelliJ itself. This allows me to, via an easy shortcut, instantly populate any resources changes (css, javascript, front end) or redeploy or even restart the server. Especially with a small application this works very well.
It is yet to be determined whether this would still work with a multi-module setup and a larger project size.
Should you want more information on how this configuration can be achieved, feel free to send me a direct message.

Need help to deploy Java web application

Hi I'm totally new to development. I'm trying deploy a web application on a local server like glassfish/tomcat. Backend of the app is written in Java and ui is created using HTML/css/js . I'm using maven as well. I'm not able to find a way to get this running on intellij CE .
Apparently this functionality is not supported in CE. Can someone suggest a turnaround or a different IDE as good as intellij idea. I've tried eclipse but I didn't find it completely useful
Thanks
There is no IDE as good as IntelliJ. JetBrains makes the best IDEs on the market.
No, I don't work for them. I have no affiliation at all. I'm just a satisfied customer for the past 13 years who is happy to buy a license with my own money every year.
The comparison matrix for community and ultimate editions makes it clear: You cannot deploy in IntelliJ without a licensed copy.
You can create a WAR file and deploy it manually to Tomcat or Glassfish if you wish. Why not just do that?
I will compliment you on how you are approaching the problem. IntelliJ, Maven, and your other choices are very good.
If you feel up to the challenge, you can look into Spring Boot. You can run an executable JAR and leave Java EE app servers behind. IntelliJ community can easily run a Spring Boot app.
Choosing Spring Boot does mean leaving EJBs behind. Everything you can do with Java EE is available in Spring Boot. You'll be using POJOs.

Grails 2.1.0 Not Auto-Reloading / Auto-Recompiling

Seems that Grails does automatically recompile my GSP pages, but not my controllers. It used to work with the previous version of Grails. Any idea what I can look for?
Using Grails 2.1.0 on OSX Snow Leopard.
Note: This is similar to this issue
Disclaimer: Auto-reload has always worked for me on my Mac.
I've found a couple of things that might be useful.
First, it appears that running a custom environment (that isn't dev) disables auto-reload (see this stackoverflow post), so you'll want to follow the directions in that post if you're running the application that way.
Second, if you're running the app as a war, for sure auto-reload is turned off. (See the Grails Auto-Reload Page)
Third, I've found that using a Grails IDE (such as IntelliJ or SpringSource) really adds a lot of stability to the Grails development environment. For example, IntelliJ doesn't use the Grails shell file that comes with the binary download. It manually invokes the Grails jars and bootstraps.
My questions to you are:
What does the rest of your environment look like? How are you running your application (run-app or another container)?
What Grails plugins do you have installed (the Grails documentation says the tomcat plugin is configured for optimal auto-reloading)?
Do you have any other Grails binaries downloaded on your computer (could cause confusion when it's trying to load)?
And finally, are you able to reproduce this issue in a clean environment (meaning new Grails binary, fresh Grails create-app)?
I'd also recommend reading the Deployment section of the Grails documentation (found here). It has some pertinent information regarding the reloading.
I apologize for the longwinded and potentially non-answering answer, but I hope this has sparked an idea or two. Let me know how things turn out!
If you name the package names on your controllers incorrectly (as in the folder structure does not agree with the package declaration), the application will still run and no errors will be reported, but auto-reloading will not work.
I had this problem when I had a BaseController class from which other controllers were derived. If I make changes to BaseController class such as adding a method or closure, change a method name, import some classes etc, the whole class reloading feature in Grails will come to a grinding halt.
The only solution that worked for me was to delete the target directory into which all classes were compiled. At least that way I did not have to restart the server every time which saved me from having to wait about 30 seconds to display the start page. It could be pretty annoying when class reloading feature does not work as expected.
Grails auto-reloading feature is not without quirks. Some of these quirks are ultimately related to java and how class loading works in servlet container environment. I hope the Grails team will make it a priority to provide seamless class reloading for Grails like other scripting environments( ruby, PHP, python or play framework) because some other aspects of this framework is such a pleasure to deal with.
Strange, I've never had a problem with this. Are you sure that your controllers are compiling correctly, no typos? I've found that it generally only takes a second or two to see a change reflected in the controllers. Domain object changes require a restart (they usually wipe your saved data) and I've found that sometimes a change to a spring managed resource (like an injected service) dont' take. But controllers and GSP pages recompile 97% of the time :)
I go between GGTS (eclipse) and the command line run-app and it almost always works for me. Are you doing any sort of caching perhaps? I'm running JDK 1.6 on Lion, grails 2.1.1
Usually you will see output telling you that a file has recompiled within a second or two of hitting save.

Java web development without Eclipse

I'm interested in doing some Java web development but I'm not really interested in using Eclipse. I have used Eclipse in the past and to me it seems to add a layer of abstraction that I'm not really interested in. However, I'm having a bit of upstart problems.
Does anyone have any good references/tutorials in getting up and running with Java web development without using Eclipse (or any other IDE for that matter)?
Create a maven project and use one of the embedded web servers like jetty or Glassfish.
Also, this approach allows you to work with the command line directly or use either Netbeans, Eclipse or IntelliJ as your IDE as they support Maven projects. I do not think that JDeveloper can yet.
(Eclipse may require the m2e plugin from the marketplace, and it handles all the Eclipse configuration transparently and directly. Highly recommended).
You can easily do java web development using notepad only. The extra work is, you have to write some extra code (like in servlet you have to write web.xml http://www.tutorialspoint.com/servlets/servlets-first-example.htm). Same in Struts, Hibernate and Spring framework, you have to write config file in notepad.

deploying a java based web site

I have created an entire site which includes Jsp and html pages,servlets,java files,and i have used msaccess as the db.All thse have been created using eclipse.What is the best way to deploy this on the web?and how do i do it?
Any help is appreciated.
Thanks
This is what the WAR-format is designed for.
Look into how to package your stuff in a WAR form and use that. Note that very few sites offer both Java and Access. You may want to consider being database agnostic.
do you already have a "java-capable" webserver running somewhere? Are you going to host it yourself or are you going to deploy it to some server hosted by some company?
As YK-47 already said tomcat (http://tomcat.apache.org/) in conjunction with apache webserver is a good choice. You might also want to have a look at jetty (http://jetty.codehaus.org/jetty/)
As soon as you have the server running and accessible over the web you can deploy any java based web application there (i.e. a war-file).
A War file is definitely the easiest method.
If you turn your project into a Maven project it can automatically generate a war file for you, and even deploy it to a webserver if you set it up to do so.
m2eclipse is the plugin you need to get for eclipse, you can then right click your project and go to Configure>Convert to Maven Project. Once this is done look in the Pom file it generates for you and select your output to war (I think by default it might be jar)
If you are new to Maven their website has a quick start guide which may be worth running through which will get you up to speed fast
5 Minute Test
It is worth he effort to learn how to use Maven as in the long run will save you a lot of time... as you wont have to write build scripts

Categories

Resources