Interrogation about Yeoman, Maven and the location of Thymeleaf HTML templates - eclipse

I recently discovered Yeoman, a tool that greatly facilitates JS dependency and build lifecycle management.
Furthermore, I use Maven as my Java dependency and build tool. I am actually seeking to integrate both tools so that I get the best of both worlds.
It seems the community has put a lot of effort into Maven/Yeoman integration with various articles such as this one: http://addyosmani.com/blog/making-maven-grunt/ as well as a yeoman-maven plugin: https://github.com/trecloux/yeoman-maven-plugin
Last, I use Thymeleaf as my Spring-MVC templating solution.
Assuming the following directory layout (see yeoman-maven-plugin above):
pom.xml
- src
- main
- java
- webapp
- …
- test
- ..
- yo
package.json
component.json
Gruntfile.js
- app
index.html
...
- test
...
- dist
...
My question is where should my Thymeleaf templates reside?
Under the yo/app directory? (they would be subsequently copied into appropriate directory by maven)
Directly under the src/main/webapp/WEB-INF/templates directory?
What I can't figure out in the case of an AngularJS application for instance, is when and how templates/pages including server-side content can interact with the servlet container given that Yeoman assumes they live under its app directory...

If you are using Thymeleaf as your templating engine with Spring, I assume you have something like
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
</bean>
In other words, your templates should reside in the folder specified in the ServletContextTemplateResolver property prefix. In the above example, that's /WEB-INF/templates. These should therefore be in /src/main/webapp/WEB-INF/templates.
If you are not using a ServletContextTemplateResolver, but instead using a ClassLoaderTemplateResolver, you can put them anywhere on your application classpath and specify it in that bean's properties. There's also a FileTemplateResolver in which you can specify an absolute path to anywhere on your file system.
When building the application with Eclipse (maven plugin), having the folders
/src
/main
/webapp
/WEB-INF
/templates
/some-template.html
/index.html
/java
/com
/yourcompany
/Main.java
/resources
/some-properties.properties
maven will generate the following
/WEB-INF
/templates
/some-template.html
/index.html
/classes
/com
/yourcompany
/Main.class
/some-properties.properties
As a expanded .war and provide that to your servlet container, ex. Tomcat.

Related

How to get logging info for HikariCP

Using Hibernate 4.3.1, Hikari 2.3.2.
I have configured this in the hibernate persistence xml
...
<property name="hibernate.hikari.leakDetectionThreshold" value="3000" />
<property name="hibernate.hikari.poolName" value="KikariTest" />
<property name="hibernate.hikari.registerMbeans" value="true" />
And this in my log4j.properties
log4j.logger.com.zaxxer.hikari=DEBUG
log4j.additivity.com.zaxxer.hikari=false
Im not seeing any logging information printed. Any ideas?
It took me a whole day to get this right! Turns out I was using log4j libs only, whereas a needed to include the slf4j libs.
I think you want log4j.additivity.com.zaxxer.hikari=true (or not set at all, left at default). additivity=false means don't inherit the parent's appender, which probably means there is no appender at all.
Remove theese jars from your classpath or lib directory if you have.
logback-classic-1.1.7.jar
logback-core-1.1.7.jar

Change metadata and artifact Repository names with p2 and Ant builder from build.xml file

I want to change the name of my resulting repositories when running a Ant build for a deplayable feature from:
"repository name='file://buildRepo - artifacts' t.."
to a more friendly one. i have tried using
...
<property name="p2.metadata.repo" value="file:${basedir}/buildRepo"/>
<property name="p2.metadata.repo.name" value="Friendly Name"/>
<property name="p2.artifact.repo" value="file:${basedir}/buildRepo"/>
<property name="p2.artifact.repo.name" value="Friendly Name"/>
..
<eclipse.gatherFeature
metadataRepository="${p2.metadata.repo}"
metadataRepositoryName="${p2.metadata.repo.name}"
artifactRepository="${p2.artifact.repo}"
artifactRepositoryName="${p2.artifact.repo.name}"
buildResultFolder="${feature.temp.folder}"
baseDirectory="${basedir}"
/>
...
The p2.gathering is not used so that these cand apply (as documented in the Eclipse wiki).
What am i doing wrong?
After the generation of your repo you can use the p2.mirror ant task to accomplish this. A detailed description of the task can be found here. Eclipse p2 mirror help.
<p2.mirror source="${p2.artifact.repo}">
<destination location="file:///${p2.artifact.repo}_beautifulName" name="p2.repo.name" />
or separte mirror tasks for metadata and artifact if you need them.

How can I add midlet version number from Manifest to compiled package name automatically in Eclipse?

I'm developing program for Cinterion TC65 wireless module. It has OTAP feature, and I need to specify application version on the server by adding a version number to file name.
I need to have something like this when compile my midlet.
MyApplication-${deployment.number}.jad
MyApplication-${deployment.number}.jar
Is there a way to do this when I create jar and jad file for each version in Eclipse (version number increments automatically)?
ANT build tool can automate build/deploy tasks & use variables.
Below is part of an old sample Ant build file with Antenna:
<project name="MyProject" default="build">
<property name="wtk.home" value="C:\WTK2.5.2_01"/>
<property name="midlet.version" value="1.0"/>
<property name="midlet.file" value="MyProject_${midlet.version}"/>
<taskdef resource="antenna.properties" classpath="./antenna-bin-0.9.13.jar"/>
<target name="build">
<wtkjad jadfile="./dist/${midlet.file}.jad" version="${midlet.version}" update="true">
<!-- MIDlet and attributes -->
</wtkjad>
<wtkpackage jarfile="./${midlet.file}.jar" jadfile="./dist/${midlet.file}.jad">
<!-- fileset with classes and resources -->
</wtkpackage>
</target>
</project>

Deploying a JavaFX 2 application with referenced jars, using Ant

I have written a JavaFx 2 application (using Eclipse on a Windows platform) and now I want to deploy it to a "clickable" jar-file. My application uses resource-code from a separate jar-file (in Eclipse, this resource code is a separate Project from the JavaFx application project).
With my Ant build.xml, I have compiled the code for both the application and the resource code and created two jar-files:
fxdemo.jar - A jar for my JavaFx application code
guifw.jar - A jar for the resource code referenced by the JavaFx application.
As a last step (I thought), using the JavaFX Ant tasks, I wanted to bundle these two jar-files to a "clickable" jar that starts my JavaFX application. I tried doing just that with the below extract from my build.xml.
<target name="deployFx" depends="fxdemo.jar" description="Releases FxDemo">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
<copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>
<fx:application id="FxDemoGUI" name="Fx Demo GUI" MainClass="com.demo.main.MainGUI"/>
<fx:resources id="jars">
<fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
<fx:fileset dir="delivery/lib" includes="guifw.jar"/>
</fx:resources>
<fx:jar destfile="deploy/fxDemoGui.jar">
<!-- Define what to launch -->
<fx:application refid="FxDemoGUI"/>
<fx:platform javafx="2.1+">
<fx:jvmarg value="-Xms32m"/>
<fx:jvmarg value="-Xmx32m"/>
<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
<property name="user.language" value="en"/>
<property name="user.country" value="GB"/>
<property name="CSS_ID" value="NIGHT"/>
</fx:platform>
<fx:resources>
<fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
<fx:fileset dir="delivery/lib" includes="guifw.jar"/>
</fx:resources>
<manifest>
<attribute name="Implementation-Vendor" value="${fxgui.vendor}"/>
<attribute name="Implementation-Title" value="${fxgui.title}"/>
<attribute name="Implementation-Version" value="1.0"/>
</manifest>
<fileset dir="delivery"/>
</fx:jar>
However, afterwards when I try to start the application (by either clicking the jar or starting from command line with java -jar appname.jar) it seems as the application can not find the Main class:
JavaFX Launcher Error
Unable to find class: com.demo.main.MainGUI
C:\Program Files\Java\jdk1.7.0_09\bin>java -jar C:\MEKMAN\Clearcase_Views\wmarekm_ss_gambau\amb_c2_prototype\javafx\prototypeGUI\deploy\fxDemoGui.jar
java.lang.ClassNotFoundException: com.demo.main.MainGUI
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.javafx.main.Main.getAppClass(Main.java:506)
at com.javafx.main.Main.launchApp(Main.java:622)
at com.javafx.main.Main.main(Main.java:805)
When I studie the created MANIFEST.MF (in the created jar-file) it looks pretty much as what I expected.
Manifest-Version: 1.0
JavaFX-Version: 2.1+
implementation-vendor: MyVendor
implementation-title: MyfirstJavaFxDeploy
implementation-version: 1.0
JavaFX-Application-Class:com.demo.main.MainGUI
JavaFX-Class-Path: fxdemo.jar guifw.jar
Created-By: JavaFXPackager
Main-Class: com/javafx/main/Main
... but then again, it doesn't work so obviously I have done something wrong.
I also tried including the classes-directory (the output folders from each of the two Eclipse/projects) by adding:
<fileset dir="../guifw/classes"/>
<fileset dir="classes"/>
Then, the launcher does find my main class (com.demo.main.MainGUI) but failes to run correctly because it lacks the -D argument that I tried to specify with:
<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
So, if you have read this far, my questions are:
Why can't the launcher find my main class in the referenced jar (fxdemo.jar)?
What have I done wrong when it comes to specify my -D arguments to the application?
Best regards
I studied/tested the fix presented in post (2012-apr-12 03:32) in the link from #Anders Petersson:
Link from #Anders Petersson
From what I can see, this is a workaround that unbudles any used jar-file (in my case; guifw.jar & demofx.jar) within the resulting jar file (fxDemoGui.jar), much like adding the classes-folders from my two Eclipse-projects (as described in the question).
I adjusted the example to my build.xml and got it to work after one slight addition:
<target name="dist" depends="fxdemo.jar">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
<copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>
<fx:jar destfile="predeploy/fxDemoGui.jar">
<!-- ADDITION -> Adds the Launcher's Main class to the resulting jar (com.javafx.main.Main)! -->
<fx:application id="FxDemoGUI"
name="Fx Demo GUI"
mainClass="com.demo.main.MainGUI"/>
<fileset dir="delivery"/>
</fx:jar>
</target>
In the dist-target from the example, I had to add:
<fx:application id="FxDemoGUI"
name="Fx Demo GUI"
mainClass="com.demo.main.MainGUI"/>
Without it, the resulting jar-file did not have the necessary com.javafx.main.Main-class and hence, failed to start.
So, this solution presents a useful workaround for my question 1)
Still, I'd be grateful if anyone comes up with a solution on how to keep the jar-files intact within the resulting jar/file.

Problems with classpath between Eclipse, Tomcat and JUnit in Spring 3 app

I have web app, based on Spring 3.0.3, that I've been developing using Eclipse 3.4. While doing so I've been running the web app in Tomcat 6.0.18 from Eclipse. That is, I have Eclipse use the Tomcat installation meaning that Tomcat will, as need, modify files etc. (at least, that's my understanding of what it's doing).
My problem is specifying the values for the contextConfigLocations in the web.xml. When running from within Eclipse this worked fine:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
classpath:applicationContext-security.xml
</param-value>
</context-param>
However, when I package the app into a war file (ROOT.war) and then added it to Tomcat's webapp directory and the try to start Tomcat, I get an error that neither of these applicationContext files can be found. But when I change it to below, Tomcat can find the files:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext.xml
/WEB-INF/config/applicationContext-security.xml
</param-value>
</context-param>
I should note that applicationContext.xml includes other applicationContext files that also use the classpath: short hand. When running within Tomcat, I need to drop all use of classpath: in favor of relative paths to get Tomcat to see these files.
Great. Tomcat and Eclise are getting along nicely. But JUnit 4.7 is no longer happy. For whatever reason, files specified using #ContextConfiguration in a test class can't be found unless the classpath: short hand is used. Here is an example:
#ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:applicationContext-security.xml"})
public class UserDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
#Test
public void testCreateUser() {
}
So applicationContext.xml and applicationContext-security.xml are found without a problem; however, property files that are specified in applicationContext.xml are not found.
<bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>/WEB-INF/config/spring/base.spring-config.properties</value>
<value>/WEB-INF/config/spring/local.spring-config.properties</value>
</list>
</property>
</bean>
But if I specify the location of these files using the classpath: short hand, the property files are found. If I do this though, the files won't be found when running from a war file in Tomcat.
For now I've created a applicationContext-test.xml that is a cut-and-paste conglomeration of all of the other applicationContext files wherein I'm using the classpath: short hand. This seems hacky and error prone and I'm wondering what the issue might be across all of these technologies.
Feedback most welcome!
web.xml content should look like
<context-param>
<description>
Spring Context Configuration.
</description>
<param-name>contextConfigLocation</param-name>
<!-- spring loads all -->
<param-value>
classpath*:spring/*.xml,
classpath*:spring/persistence/*.xml,
classpath*:spring/webapp/*.xml</param-value>
</context-param>
see http://static.springsource.org/spring/docs/2.5.x/reference/resources.html#resources-app-ctx-wildcards-in-resource-paths for further reference
the junit config should follow the same convention with classpath*:
but beware spring might load .xml context files you don't want it to do