iceant / demo-rocker-spring-boot-starter

Demo for rocker-spring-boot-starter
1 stars 2 forks source link

Jar artifact does not include compiled .class templates #1

Open damir78 opened 5 years ago

damir78 commented 5 years ago

Hi @iceant

I did tested you nice rocket demo. Currently if using mvn package - the jar does not include compiled generated tmplate classes (.class) into folder BOOT-INF/classes/templates/ . Ohnly .html files. If I try to start java- jar ` [Request processing failed; nested exception is com.fizzed.rocker.TemplateNotFoundException: Compiled template security/login not found] with root cause

java.lang.ClassNotFoundException: Class security.login not found at com.pointcx.rocker.spring.boot.starter.reload.RockerClassLoader.loadClass(RockerClassLoader.java:44) ~[rocker-spring-boot-starter-1.2.1.jar!/:1.2.1] `

It works fine if I start DemoRockerSpringBootStarterApplication directly from IDE (Intellij)

I think the problem is: rocker plugin uses login.rocker.html pattern for compiled files. Now it is just login.html

damir78 commented 5 years ago

image

damir78 commented 5 years ago

I've noticed if starting frrom IDE- your rocker-s-b-starter creates @runtime in target/classes the related class like target/security/login.class. But if strarts using java -jar blah.jar you can't create class inside jar file (classpath, etc). I think you should use the default maven plugin from rocker templates to create jar- artifacts

image

iceant commented 5 years ago

Hi, @damir78 thanks for feedback. Rocker had 2 seperated package, compiler and runtime package. compiler will generate source code from template, and runtime only use compiled class from classpath. I don't like to do configuration in different place, so I moved the configuration from maven pom to application.properties for rocker-compiler. I need to render .js, .css and other files with difference extension name, only support .rocker.html is not engough for me. So far, the rocker-spring-boot-starter will check the compiled class first, if it can not find the compiled template class, it will try to compile the template to class. The default implementation in rocker is based on file system. We can not use classpath resource to load as string and compile it to class. It's not easy to do that at runtime. Maybe that's possilbe to modify rocker's compiler to make that happen. But, it will take too much time for me. What make Rocker so fast? It's compiled template engine. So, at development phase, we can use file system based compiler. After the test, we can package to a jar file, and run it. At runtime, everything is just class. I don't like the default maven based plugin, it's too complex for me. You need to do configuraiton in pom.xml, and run maven generate-sources everytime the template changed. I would like to change the temlate, then refresh the page, everything is reloaded. It works fine for me. Saved lots of time for me. This feature could have memory issue by using classloader to reload classes. But it's just happend at development phase, I can accept that.