I wonder if there is an example which html files and java files are resides in different folders.
views:
1727answers:
7I don't recommend using a separate page directory unless you are quite comfortable with how resource streams work, which I am not.
The vast majority of wicket projects I have seen keep class and html files in the source directory. I tried separating them myself but then found that getting my hands on other resources, like images and such, was a hassle; so, I wound up putting those resources in the package directory - in the end I had resources in several different places and it was more of a mess than putting everything in package directory would have been.
That said, here's the code I used to put my html templates in a separate folder. It should be added to Init() in your application class.
IResourceSettings resourceSettings = getResourceSettings();
resourceSettings.addResourceFolder("pages"); //the full path to your folder, relative to the context root
resourceSettings.setResourceStreamLocator((IResourceStreamLocator) new PathStripperLocator());
http://cwiki.apache.org/WICKET/control-where-html-files-are-loaded-from.html has a tutorial on this.
This is one area where using Maven to manage your project is very nice. Since Maven has two locations that are included on the classpath, you can logically separate the Java source and the HTML files and still have them maintain the same package structure. The Java code goes into src/main/java and the HTML goes into src/main/resources. When building or running the code both of these locations are added to the classpath.
If Maven isn't for you perhaps this idea could be applied to whatever environment you are using.
I use Maven (as the user above points out) and typically put all my .html pages in src/main/resources/same/package/name/as/corresponding/java/file
I find this works nicely as my designers can checkout the base package from the resources folder and they don't get confused by all the .java files (and more importantly they don't accidentally change them!)
I made a post to the mailing list if you are interested.
I use seperate folders for my java and html wicket source files, but my ant build process then copies the html to the classes folder of my web app so i avoid issues of having to setup wicket resource settings.
My basic build.properties has
web.root = ${project.home}/web
web.java.dir = ${web.root}/java
web.html.dir = ${web.root}/html
war.root = ${project.home}/war
web.inf.dir = ${war.root}/WEB-INF
war.lib.dir = ${web.inf.dir}/lib
war.classes.dir = ${web.inf.dir}/classes
wicket.version = 1.3.5
wicket.jar = ${war.lib.dir}/wicket-${wicket.version}.jar
wicket-extend.jar = ${war.lib.dir}/wicket-extensions-${wicket.version}.jar
wicket-spring.jar = ${war.lib.dir}/wicket-spring-${wicket.version}.jar
and the compile / assemble ant targets look like
<target name="compile-web">
<path id="wicket.build.classpath">
<filelist>
<file name="${wicket.jar}"/>
<file name="${wicket-extend.jar}"/>
<file name="${wicket-spring.jar}"/>
<file name="${externaljars.path}/spring/2.5.6/spring.jar"/>
</filelist>
</path>
<javac destdir="${war.classes.dir}" classpathref="wicket.build.classpath"
debug="on" srcdir="${web.java.dir}">
<include name="**/*.java"/>
</javac>
</target>
<target name="assemble-war" depends="compile-web">
<copy todir="${war.classes.dir}" overwrite="true">
<fileset dir="${web.html.dir}"/>
</copy>
<delete file="${dist.dir}/validationservice.war"/>
<war destfile="${dist.dir}/validationservice.war" webxml="${web.inf.dir}/web.xml" basedir="${war.dir}">
</war>
</target>
I'm not a fan of having the HTML files residing inside the src/main/resources
folder. I think the simplest way to handle this and obtain a clean separation in version control and within your project is to use the last set up in the Wicket article linked by perilandmishap:
<project>
[...]
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/html</directory>
</resource>
</resources>
[...]
</build>
[...]
</project>
So, now all your HTML files will be in the new, separate HTML folder but still merged with your Java classes. Just remember you would still use the package naming scheme within the HTML folder, i.e. src/main/html/com/your/package
I would put Java and HTML files into the same folder. That would make it much more comfortable to pick the HTML file corresponding to a Java class. Think of a components HTML file as a sort of UI description that would otherwise be written in Java (like with Swing).
Is it possible to have many dynamic resource folders? I'd like to use different HTML folders so that each user could chose his own skin template. I didn't find any help on that topic...