The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

shivkpr (30) [Avatar] Offline
#1
Hi Neal,
Instead of using Tomcat, I'm trying to look at the flow of the process via jdevleoper.I'm having problem with the finding the templates

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'ViewSchedule.vm'

I know there are 2 .vm and I've tried putting in web-inf and also same area as the velocity.properties fil but no luck. Is tehere another way of speifying the full path of the .VM files. I also tried look at the jar file

any help apreciated
thanks
nford (36) [Avatar] Offline
#2
Re: Using Velocity
Finding the templates is actually not trivial (as you are seeing). The best way to do it is to load them from the classpath, with the templates residing in a JAR file. If you look at the Velocity documentation, is includes discussions of the best ways to load the templates. The least preferred way is to try to load them by referencing their names directly.

Revisit the material in the section on Resource Loading for my discussion of finding the .vm files. When building the project, you need to .JAR the .vm files and place them on the servlet container's classpath (like in the /WEB-INF/lib directory.
shivkpr (30) [Avatar] Offline
#3
Re: Using Velocity
Hi, there are 2 jar file that I can see
velocity-dep-1.3.1.jar
velocity-1.3.1.jar

are the .VM files in these jar files

also when i try to view these jar files via

java -jar tf velocity-dep-1.3.1.jar

I get system cannot find the file specified

if the VM files are not in the jar files do i create one

please instruct how to do this and naming conventions used


my properties file has the following


resource.loader = class
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

runtime.log = velocity.log
nford (36) [Avatar] Offline
#4
Re: Using Velocity
You must create your own jar files, which include the .vm files. If you look at the Ant build file for the project, it includes a task to do this:

<target depends="resource" name="archive">
<jar compress="false" destfile="root/WEB-INF/lib/templates.jar">
<zipfileset dir="resources/templates" fullpath="ScheduleEntryView.vm" includes="ScheduleEntryView.vm"/>
<zipfileset dir="resources/templates" fullpath="ViewSchedule.vm" includes="ViewSchedule.vm"/>
<fileset dir="${dest}">
<patternset refid="dest.exclude"/>
<include name="./resources/templates/*.vm"/>
</fileset>
</jar>
</target>

It builds a JAR file named "templates.jar" and places it in the /WEB-INF/lib directory. Using Ant to build the project is much easier than trying to do it by hand.

You can use Ant just to build the templates file if you like. Once Ant is installed, issue the following 2 commands:

ant init
ant archive

It will generate the template.jar file. If you want to build it by hand, or use JDeveloper, you must get it to produce a JAR file that looks exactly like the one I've attached to this message. You can use the attached one, but if you want to build it yourself, you should create one that has the same contents (including the directory structure).
shivkpr (30) [Avatar] Offline
#5
Re: Using Velocity
thanks neal, I'll hve to have a look at ANT again. I've used your template and it seems to be fine. However I would like to know how to build it manually
also
I've seen
HttpSession session = request.getSession(true) and also
other place with False. not sure what its doing in this context. I presume True, create a new session but not sure on the false

Also could not work out what
System.arraycopy(scheduleBean.getDisplayColumnHeaders(),
1, displayColumns, 0, numOfDisplayColumns)
does in this example

many thanks again
nford (36) [Avatar] Offline
#6
Re: Using Velocity
>> HttpSession session = request.getSession(true)

getSession(true) returns an existing session or creates a new one
getSession(false) returns an existing session or null if one doesn't exist

These are both part of the standard Java web API's

>>System.arraycopy(scheduleBean.getDisplayColumnHeaders(),
1, displayColumns, 0, numOfDisplayColumns)

Copies one array into another array. Check the JavaDocs for System.arraycopy(). In this case, copies the bean's columnHeaders array into displayColumns, so that I don't have to pass the entire scheduleBean object, just a copy of the array.