I'm just starting to learn Spring reading "Spring In Action" and I cannot get my image to load on anything other than port 8080 (where tomcat launches). This would be fine normally, but I have to keep restarting the program to load any changes to my webpage.
Intellij tries to run my web program on port 63342, but no images load, only text. I believe this is an issue with Thymeleaf. I tried pointing tomcat to port 63342 but it won't load (port is in use?)
I would like it to where I can get the reload on save feature to work, and especially being able to use the shortcuts in intellij to launch the web page.
Any suggestions?
Basically the problem is, as I understand, that you're trying to open your .html template directly from IDEA. Which means you're not using the thymeleaf engine to render it - you're just opening the template itself and not the resulting page. If you open the source code of this page using your browser's dev tools, you will see that all your expressions stay unprocessed which leads to it trying to fetch the resources on the wrong port (e.g. 63342 instead of 8080 where your application is really running and is ready to serve the resources).
Thus, you cannot edit your templates like this. But Thymeleaf does have an option to do that. If you're running your Spring Boot application from the IDE directly (e.g. a profile in Intellij IDEA Ultimate) you can add the following to your application.properties:
spring.thymeleaf.cache=false
This will tell your Spring template resolver that you do not want to cache your .html templates and it will load the files from disk every time, so if you modify your template and then hit IDE's build button it should re-package your template and when you refresh your page in browser it will load (and process!) the edited one.
Caution! Only use this for development builds, set value to true for production environments to prevent unnecessary re-reading.
See Spring Boot Docs on Hot Swapping for more.
if you want intelj to display your image you have to add a regular src and add a th:src to show the image when the program is run. Try adding both
<img th:src="#{/assets/img/image.svg}" src="../static/assets/img/image.svg"/>
Related
I am working on a Java servlet project using NetBeans.
I am looking for a way to use NetBeans’s “deploy on save” on another browser of my device within LAN (locally its working fine) so that I don’t have to manually reload my browser during my development.
Recently I have decided to use proxy feature of Browsersync, but the problem of the Browsersync is, it auto reloads browser early before NetBeans completes deployment on save.
I am using GlassFish(4.1) with NetBeans.
Any help is greatly appreciated.
I had to something different in order to achieve the solution.
I am watching “glassfish/domains/domain1/config/” folder using Browsersync. Looks like after building the project, few files modified here during hot reload (so I have used watchEvents from Browsersync).
The proxy site instantly reload after NetBeans completes deployment on save.
Following is the Browsersync command.
These directory names have to be the full path with drive letter.
browser-sync start --proxy "http://localhost:8080/test" --files "src/java/com/test/, glassfish/domains/domain1/config/" --watchEvents add change " src/java/com/test/, glassfish/domains/domain1/config/" --no-notify --host 192.168.X.X --port 5000
I am making a dynamic web page in eclipse ee environment using tomcat. When I change the image name to a different image (this different image was added afterwards), then the changes are not reflected on the webpage. I think I have already uploaded the image file on the tomcat server and I dont know how to change the image resources again. But if i make syntax changes they are reflected on the webpage. Please help.
There is no way to change the application properties on the Tomcat running.
You need to stop the Server(Tomcat) and make the changes in Application whatever you need...finally you can run the server again that changes will update in the web page.
It seems when I manually build my gwt app, and run it on jetty, i get a blank page. I could add tags within the html document and see its content (ex add a table, i would see a table). But it seems like the modules javascript is never loaded.
This would be the command I manually run: mvn gwt:compile jetty:run
When I run my app on GWT Development Mode using their IDE, everything shows up as expected, I see my module being loaded and its contents.
Note I am using the RootLayoutPanel, would I be required to use UI binding?
If Development Mode works but compiled & deployed files do not, well, it looks like a deployment issue. To check, get Firebug for Firefox (or the equivalent tool for your preferred web browser), and check the HTTP requests made when the page is loading - you will probably find that some requests are 404, and that GWT compiles JS hasn't been copied over to the proper spot.
I am writing a java web-application program to create a file(a simple xml file) in hard disk. The program can update the file dynamically. After its creation/update, I want to see the contents of that file from another application(e.g. browser). The problem is that the browser is not aware of the new modifications made in the file. This is resolved if I refresh the eclipse project manually(However, I want the browser to see updated file contents each time I refresh the browser after the file is modified within the web application). So, I think there's some issue with Tomcat/java not releasing the handle of the file or maintaining cache.
Please suggest.
No, the issue is not with Tomcat. It's with Eclipse. You must refresh your eclipse project vs the project directory on disk.
The alternative is to use external Tomcat (or Jetty) for testing your webapp.
Set Response no-cache headers.
I've heavily edited this question because responses indicated I wasn't being clear
problem: UI changes to a Java web project can be tedious and time consuming because every web-app file is contained within the WAR
my proposed solution: Manage the JSP's, CSS, JS and Tags separately from the application code base which for the purpose of this question I'm defining as:
All Java Source Code
Custom Tag Libraries With Compiled Java (extending TagSupport)
Spring Configuration Files
Web.xml
Jar's
+ Source
+ WEB
- WEB-INF
- JSP
- Tags
- lib
- HTML
- CSS
- JS
What would be nice is if after the major initial release and maintenance cycle, changes to view files could be treated as a different kind of release than a change to the Source. Source changes would be committed normally, and the application version would change. However, a change to a CSS/JS/HTML and even a JSP could be made in a test environment that is internally viewable to test new looks, add links, and so on. Technically, a JSP could even be added and as long as the controllers (like mine do) can be configured to show new JSP's without any Source modification, pages could be added without any deployments.
USE CASE - Owner of the site is running a promotion, he has a fancy graphic to link to an informational pure HTML page and wants it added to the home page.
Now imagine this work-flow:
UI dev opens dreamweaver and can FTP into Staging (staging may be a bad name, but basically a live test server). He can see:
- JSP
- Tags
- HTML
- CSS
- JS
Now he brings in the HTML file with information on it, adds it to the HTML directory. He then goes into JSP/home.jsp and finds the component that renders an advertisement on the right column, directly below it he adds his nifty image, saves his changes, opens his browser and goes to the live Test URL. He sees his image, but the component no longer renders the advertisement. Oops, he calls a developer and the developer says no problem
$ staging - > ./rollbackView -mostRecentBackup
The UI guy checks the site, everything is back like he never touched it.. now he more carefully adds his graphic and HTML, realizing that he cut off a JSP custom tag before. Now, QA, whatever that is for the project looks at the site, runs selenium, whatever. It all looks great. The developer gets the ok to release the changes
$ production - > ./updateProductionView
the script checks the application versions, ensuring they are identical, then copies over the view files. It's now 8:45 and the website owner (for us internal) is very happy that his new idea was implemented in the first 15 minutes of the day
Now the developer wants to create a patch that allows something cool, he updates his project, and the new view files are present. Maybe this isn't possible, but he could run a script, or use a second source repository like Mercurial to manage the views (ideas?) and he has the project and view files he needs. He makes his changes to the source, and views, whatever he needs. Now that is complete he can check in his changes and bring the WAR to a directory on Staging
$ staging - > ./deployStaging -overwriteView
The full war is deployed, and the JSP's are now what he had in his project. If the UI guys had made changes to staging, they will be overwritten (backed up maybe?). He could leave off the '-overwriteView' flag and the view files would remain untouched. At this point a full QA regression, integration and unit tests have been run, it's time to patch the main application
$ staging - > ./deployProduction
A full deploy is there, the application version is now V1.1 and everyone is happy
My Questions:
First, has anyone done something like this? If so, are there any good recommendations you can make? Development is done on Windows, but the production and staging servers are running Unix. All servers run the same version of Tomcat.
I'm looking for ideas for scripts that would allow Staging web files to be backed up, and hopefully even committed to the main project, also scripts that could take
What has been overlooked? Can I keep the project structured the same? Will this cause problems with CVS?
Is there anything that isn't possible or technically feasible here?
Can you point your UI resources to other folders? This way you set up the symlinks once on the test server(s) and allow the UI developers to manipulate the 'live' files. If these folders are source controlled then the UI devs could rollback their own changes if necessary.
http://www.isocra.com/2008/01/following-symbolic-links-in-tomcat/
If switching away from JSP is an option you could use a template system (Velocity or Freemarker for example) and store those resources outside the deployed war, on the file system or in a relational db for example.