spring dev tools does not reload maven resources - java

I have some thymeleaf templates under maven src/main/resources/template path, when I change a controller java file, spring dev tools will trigger a restart, but when I change template files, the livereload does not work. At first, my maven had some problem building the project, it failed to add the files under src/main/resources to target/classes folder, then when I start the spring boot project(using spring tool suite), it showed a error that suggested templates not found. I rebuild the project use "mvn clean package" and restart the spring using spring dash board, it's OK. So I suspect that when I change the template file, it will not impact the target/classes folder, spring dev tools still get template from target/classes instead of detecting the changed file in src/main/resources/. Is there anything I miss to configure for spring dev tools?

Did you try to reload maven dependencies in the following way: in Package Explorer right-click on a project folder and choose Maven -> Update Project (ALT+F5). It helped in my case.

Do you want to auto reload Thymeleaf templates?
You may set spring.thymeleaf.cache property to false.
Reference: 72.2 Reload Thymeleaf templates without restarting the container

Related

How to manually configure directory of spring boot project in Intellij?

I want to add an existing spring boot project into my Intellij collection project as a module.
Obviously if I open the spring boot project by itself, everything is configured correctly, but it's not configured correctly if I copy a spring boot project directly into the directory of the collection project where the modules go.
After I manually mark the directory as a sources root, I still need to set the classpath the way it would've been setup if importing the spring boot project directly.
What is the easiest way to finish configuring Project Structure for the directory so that it would work as if it was imported directly?
You can try to close the IDE, backup and delete all .iml files from your Spring project, open your main project in the IDE and use Import a module from existing sources to add your Spring project as a module.

How to run a Spring Boot maven project in VSCode and how to config the base url of a spring boot web application

I have a Maven project which I need to run from VSCode. Right now the way I do it is:
Open the project folder in VSCode. Edit the java, js, html files etc.
Start my tomcat by running bin/startup.sh; tail -f logs/* ; in the apache tomcat's directory.
Open terminal in the project directory and run mvn clean install -DskipTests.
Then run cp /Users/path-to-my-project/target/myWebApp.war ~/apache-tomcat-8.5.23/webapps/ to copy the war file into the tomcat's webapp directory.
After which I can access my web application at localhost:8080/myWebApp.
Is it possible to do all of this in one click (or command) in VSCode. I know it can be done in Eclipse or IntelliJ but I want to work with VSCode.
I have installed the Spring Boot Extension Pack and Java Extension Pack in VSCode. I am just confused on how to setup the path to my tomcat, build the project and then copy the war file to the tomcat webapps folder.
Is it possible to do all of this in one click (or command) in VSCode. I know it can be done in Eclipse or IntelliJ but I want to work with VSCode.
To make your webapp visitable, just type:
Ctrl+`
in the VS Code to get a terminal, and then type:
mvnw spring-boot:run
in the application there is a suffix after the locahost:8080. So something like localhost:8080/mywebapp/...rest of the url. With the above method everything works but I loose that web app name suffix. Any idea how I can get it back?
In your application.properties file(in the src/main/resources folder in your spring boot project), add below line(for Spring boot v2.0.5):
server.servlet.context-path=/mywebapp
For older version, you may need:
server.contextPath=/mywebapp
See these links for reference:
How to set base url for rest in spring boot?
What is the purpose of mvnw and mvnw.cmd files?
how to run springboot app in visual studio code? is it possible or not?

Dependencies not downloaded in Spring Tool Suite

I am creating a Spring Starter Project using Spring Tool Suite. I selected JPA, Web and Derby Database dependencies. When my new project is created the src folder displays a "?" mark as shown in the screenshot. What am I missing? Why the question mark?
Note that there's an entry called "Maven Dependencies" right above those folders. Maven doesn't download dependencies into your project, it puts them in your local repository (generally ~/.m2/repository).
The question marks have nothing to do with dependencies--they're Eclipse's indication that you haven't added those entries to source control. (Contrast with the mvnw and POM entries, which have a stylized disk pack to show they are in source control.)

Rename to web.xml when packaging using Eclipse

I have a J2EE application which has two web.xml files. One is called web.live.xml another is web.dev.xml. I am building this application with maven using profiles. So maven knows which file to choose when packaging.
I was wondering is it possible to make Eclipse use web.dev.xml when packaging my project and deploying it to Tomcat. This would be very useful because web.dev.xml sets some options which decrease start up time of the application.
You can designate the dev xml to be default (and name it web.xml). You can also have maven move (from a different folder) rather than rename.
You can use the Maven resources plugin (http://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html) and configure it with a property in the profile and use that property in the configuration of the filename.

"Module name is invalid" when exporting an existing eclipse project to a war file

I am trying to export an existing Eclipse project to a war file. But whatever I typed in the "WAR Export" dialog page, the system always returned "Module name is invalid". I do not know how to fix this issue. Thanks for the help.
I had the same issue, and I fixed it. Please follow the steps below, and you can create your war file.
Right-click on folder project.
Click on properties.
Go to project facets.
Activate, if necessary.
Scroll down to Configuration and mark Dynamic Web Module.
This works for me.
you must be sure your project is a Web Project, if it's not a Web Project check this link: http://eclipse.dzone.com/tips/converting-java-project-dynami
In Eclipse STS
Right-click on folder project.
Click on properties.
Go to project facets.
Choose your Java 1.8
Scroll down to Configuration and mark Dynamic Web Module.
After that, it works fine.
In my case error went off when the war file name matched the project name of the eclipse. Its easy to choose one from the drop down box.
If your project is a Maven project. In Export Wizard, Module name combo box will be empty and any inputs will be invalid.
Solution: If you build the project using Maven. - In project / package view Open context menu on the project > Run > Maven Build
The WAR file will be packaged in target directory.
Note: PUM file of the project should be configured for packaging WAR file.
Right-click on folder project.
Click on properties.
Go to project facets.
Choose your Java 1.8
Scroll down to Configuration and mark Dynamic Web Module.
When I follow this step getting me the error (Dynamic Web Module 3.0 java 1.6 or newer)
I'm currently using Java 11
I am not sure about the exact cause. But this gets resolved most of the times if you give the exporting project war file name just same as the project name in the IDE
When I converted my java project onto dynamic web project using eclipse for EE developers, I encountered this.
Then I made a whole new dynamic web project and copied all my source files to it, and I was able to export a war file easily.

Categories

Resources