I hope you would be fine.
I have question regarding the path for jar file where i have to put it. As i mentioned that i have i two project one is creating the jar with html file and in the second project i want to view the content inside of the jar file in the thymeleaf template.
so now i have a jar file but i don't know where exactly i have to put it to set the prefix in the configuration.
I'm going to assume the JAR is in the classpath of the second project since the discussion so far is around the ClassLoaderTemplateResolver. With that, then the prefix should include things like the path to the package the template is on, eg: if the template lives in the com.mywebsite package then an appropriate prefix would be "com/mywebsite".
When I said "JAR as part of the classpath", I imagined it was either included as a dependency of your project, or included using the -cp flag when running a program from the command line, or inside a web application's WEB-INF/lib folder. For a Spring Boot project, I'm not sure how to add a non-Maven JAR to the project. One way might be to install the JAR to your local repository, which is outlined here: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html Then you can include that JAR as a dependency and use the ClassLoaderTemplateResolver as I mentioned before.
I added the ClassLoaderTemplateResolver in my main method which looks like in below Screenshot. I am new to spring boot that's why I asking many questions but I appreciate your help. So should I make a config file to add ClassLoaderTemplateResolve? or it's ok in the main method?
I am able to show the contents of the Iview project but I am not able to pull out the Vis.html from the jar inside the Iview project. The jar is actually created in the second project "Visualizer".
Here you can see both the project in the screenshot.
so only I am left with this task where I have to call the vis.html to the Iview project and show it on home.html.
With the error message of "An error happened during template parsing (template: "templates/vis.html")", I'm led to believe that it managed to pull out vis.html, but Thymeleaf ran into an error while parsing vis.html. The full stack trace should have the cause of the error which should have more details, like if it an expression wasn't balanced correctly (like missing a closing }) or it encountered some kind of null error.
yes, you are right. if I remove the ClassLoaderTemplateResolver from the main application class the error is something like in the below Screenshot. it means the Iview side is able to pull out the HTML file from the jar.
The JAR needs to be included as a project dependency, like what you did following the video before, for the ClassLoaderTemplateResolver to be able to look into it. If it's sitting in the resources directory, then it won't be expanded as part of the classpath and so the ClassLoaderTemplateResolver won't find it.
If you really want to have your JAR sitting in the resources directory, then you'll need to write a custom template resolver (implement the ITemplateResolver interface or extend AbstractTemplateResolver) to read the JAR, and then peek into its contents to extract the necessary template.
Thank you very much.
you are really very co-operative.
For the ClassLoaderTemplateResolver where exactly I have to put the jar file to be counted as a classpath? I am just asking about it but I am also trying to configure ITemplateResolver.
and one thing more in my controller in return it shows "Cannot resolve MVC view 'vis' and actually this 'vis' is in the jar file and MVC cannot see it directly so what you say maybe because of this the error "template could not be resolved is coming"
To have the JAR on the classpath so the ClassLoderTemplateResolver can work, it needs to be included as a dependency of your project. For example, if you're using Gradle, then dependencies live in a section like this in the build.gradle file:
For Maven, it'll be in the pom.xml file, probably in the <dependencies> section, though I'm not very good with Maven so can't give a good example.
(Didn't you have this going after you followed that video? Your error page was talking about errors in the vis.html template file?)
As for IntelliJ not being able to resolve "vis", I wouldn't worry about that as you've got a special case trying to load templates from a JAR - IntelliJ I think only scans for template files, not files inside other files.
In the console, the first error is about parsing and the second error is about vis template resolving
I followed the video and I added the jar using the terminal using the following command first time :
Yes, you can load templates from anywhere provided you have the appropriate TemplateResolver for the job. Thymeleaf comes with 4 template resolvers:
Most of the examples you've seen probably use the ServletContextTemplateResolver, which can load anything from the context root of your web application. I've used it to load stuff from the main web content directory instead of WEB-INF - just a personal preference.