How to use @velocityproperties in Velocity file to refer to classpath?

I use Velocity templates for HTML mail templates in a Java application.

It includes a common template with #parse:

#parse( "defaultMailTemplate.vm" )

Idea cannot resolve it and proposed to use @velocityproperties

It's my first time using this, I can't find any reference to it in the help.

I've tried this but to no avail:

#* @velocityproperties path=classpath:defaultMailTemplate.vm *#



the defaultMailTemplate.vm in question is at the root of a JAR dependency.

Is there a way to resolve a file located in a JAR with @velocityproperties ?

I'm using #92.65
9 comments
Comment actions Permalink

Hi nodje

@velocityproperties comment is useful only if there is some
velocity.properties file in your project.

for more info, see
http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/

BR, Alexey

nodje wrote:

I use Velocity templates for HTML mail templates in a Java application.

It includes a common template with #parse:

#parse( "defaultMailTemplate.vm" )

Idea cannot resolve it and proposed to use @velocityproperties

It's my first time using this, I can't find any reference to it in the help.

I've tried this but to no avail:

    • @velocityproperties path=classpath:defaultMailTemplate.vm *#


the defaultMailTemplate.vm in question is at the root of a JAR dependency.

Is there a way to resolve a file located in a JAR with @velocityproperties ?

I'm using #92.65

---
Original message URL: http://www.jetbrains.net/devnet/message/5251219#5251219

0
Comment actions Permalink

Hi Alexey,

so isn't it a problem that IDEA's resolution proposal introduce
a@velocityproperties statement?
I don't see where the velocity.properties could help in resolving a
file's location.

Is there a way to help IDEA resolve a file in a dependant JAR in a Vm file?

rgds,
nodje

On 2009-11-30 21:57:33 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:

Hi nodje

@velocityproperties comment is useful only if there is some
velocity.properties file in your project.

for more info, see
http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/


BR,


Alexey

nodje wrote:

>> I use Velocity templates for HTML mail templates in a Java application.
>>
>> It includes a common template with #parse:
>>
>> #parse( "defaultMailTemplate.vm" )
>>
>> Idea cannot resolve it and proposed to use @velocityproperties
>>
>> It's my first time using this, I can't find any reference to it in the help.
>>
>> I've tried this but to no avail:
>> #* @velocityproperties path=classpath:defaultMailTemplate.vm *#
>>
>> the defaultMailTemplate.vm in question is at the root of a JAR dependency.
>>
>> Is there a way to resolve a file located in a JAR with @velocityproperties ?
>>
>> I'm using #92.65
>>
>> ---
>> Original message URL: http://www.jetbrains.net/devnet/message/5251219#5251219


0
Comment actions Permalink

Hi nodje

Actually, a problem is that @velocityproperties intention is active when
no velocity.properties file found. (Your project doesn't contain any
velocity.properties file, right?)
IDEA makes use of a velocity.properties file to resolve templates (*.vm
files) as Velocity engine does: considers relative paths defined by
file.resource.loader.path property to find template files.

How does your Velocity engine resolve a file in a dependant JAR in a Vm
file? Can you provide more info about those files?

BR,
Alexey

nodje wrote:

Hi Alexey,

so isn't it a problem that IDEA's resolution proposal introduce
a@velocityproperties statement?
I don't see where the velocity.properties could help in resolving a
file's location.

Is there a way to help IDEA resolve a file in a dependant JAR in a Vm file?

rgds,
nodje

On 2009-11-30 21:57:33 +0900, Alexey Chmutov <achmutov@swiftteams.com>
said:

>> Hi nodje
>>
>> @velocityproperties comment is useful only if there is some
>> velocity.properties file in your project.
>>
>> for more info, see
>> http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/
>>


BR,

>>
>> Alexey
>>
>> nodje wrote:
>>> I use Velocity templates for HTML mail templates in a Java application.
>>>
>>> It includes a common template with #parse:
>>>
>>> #parse( "defaultMailTemplate.vm" )
>>>
>>> Idea cannot resolve it and proposed to use @velocityproperties
>>>
>>> It's my first time using this, I can't find any reference to it in
>>> the help.
>>>
>>> I've tried this but to no avail:
>>> #* @velocityproperties path=classpath:defaultMailTemplate.vm *#
>>>
>>> the defaultMailTemplate.vm in question is at the root of a JAR
>>> dependency.
>>>
>>> Is there a way to resolve a file located in a JAR with
>>> @velocityproperties ?
>>>
>>> I'm using #92.65
>>>
>>> ---
>>> Original message URL:
>>> http://www.jetbrains.net/devnet/message/5251219#5251219


0
Comment actions Permalink

Hi Alexey,

I've got a velocity.properties of course. I put it in
src/main/webapp/WEB-INF/ .
I can't remember why I've chosen WEB-INF rather than
src/main/resources, but I remember it was a conscious choice, I've
unified all our application in this fashion.

I was lucky enough I had nothing to change to have Velocity resolve Vm
files in dependant JARs.
I've got no file.resource.loader.path property specified in
Velocity.properties, so the default value is in use I suppose.
Looking into Velocity jars I can't find any default though.
The only reference to "file.resource.loader.path" I can find is in
spring-context-support.jar

Are you saying setting "file.resource.loader.path" in the
velocity.properties woud have IDEA alos resolve the Vm files in the
classpath?
I'd be reluctant to do that since everything works fine without, but if
it has not impact, why not.

-nodje

On 2009-12-01 19:52:22 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:

Hi nodje

Actually, a problem is that @velocityproperties intention is active
when no velocity.properties file found. (Your project doesn't contain
any velocity.properties file, right?)
IDEA makes use of a velocity.properties file to resolve templates (*.vm
files) as Velocity engine does: considers relative paths defined by
file.resource.loader.path property to find template files.

How does your Velocity engine resolve a file in a dependant JAR in a Vm
file? Can you provide more info about those files?

BR,
Alexey

nodje wrote:

>> Hi Alexey,
>>
>> so isn't it a problem that IDEA's resolution proposal introduce
>> a@velocityproperties statement?
>> I don't see where the velocity.properties could help in resolving a
>> file's location.
>>
>> Is there a way to help IDEA resolve a file in a dependant JAR in a Vm file?
>>
>> rgds,
>> nodje
>>
>> On 2009-11-30 21:57:33 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:
>>
>>> Hi nodje
>>>
>>> @velocityproperties comment is useful only if there is some
>>> velocity.properties file in your project.
>>>
>>> for more info, see
>>> http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/

BR,

Alexey

nodje
>>>
>>> wrote:
>>>> I use Velocity templates for HTML mail templates in a Java application.
>>>>
>>>> It includes a common template with #parse:
>>>>
>>>> #parse( "defaultMailTemplate.vm" )
>>>>
>>>> Idea cannot resolve it and proposed to use @velocityproperties
>>>>
>>>> It's my first time using this, I can't find any reference to it in the help.
>>>>
>>>> I've tried this but to no avail:
>>>> #* @velocityproperties path=classpath:defaultMailTemplate.vm *#
>>>>
>>>> the defaultMailTemplate.vm in question is at the root of a JAR dependency.
>>>>
>>>> Is there a way to resolve a file located in a JAR with @velocityproperties ?
>>>>
>>>> I'm using #92.65
>>>>
>>>> ---
>>>> Original message URL: http://www.jetbrains.net/devnet/message/5251219#5251219


0
Comment actions Permalink

Hi nodje

You shouldn't modify you velocity.properties file just to help IDEA
resolve template files. The resolve should work in natural conditions
:). Moreover, the changing of the file won't help.
To ensure I get it right, let me describe your configuration:

There are a vm-file with a line #parse( "defaultMailTemplate.vm" )
and a jar-file containng defaultMailTemplate.vm,
and you just run Velocity engine with that jar-file in classpath?

nodje wrote:

Hi Alexey,

I've got a velocity.properties of course. I put it in
src/main/webapp/WEB-INF/ .
I can't remember why I've chosen WEB-INF rather than src/main/resources,
but I remember it was a conscious choice, I've unified all our
application in this fashion.

I was lucky enough I had nothing to change to have Velocity resolve Vm
files in dependant JARs.
I've got no file.resource.loader.path property specified in
Velocity.properties, so the default value is in use I suppose.
Looking into Velocity jars I can't find any default though.
The only reference to "file.resource.loader.path" I can find is in
spring-context-support.jar

Are you saying setting "file.resource.loader.path" in the
velocity.properties woud have IDEA alos resolve the Vm files in the
classpath?
I'd be reluctant to do that since everything works fine without, but if
it has not impact, why not.

-nodje

On 2009-12-01 19:52:22 +0900, Alexey Chmutov <achmutov@swiftteams.com>
said:

>> Hi nodje
>>
>> Actually, a problem is that @velocityproperties intention is active
>> when no velocity.properties file found. (Your project doesn't contain
>> any velocity.properties file, right?)
>> IDEA makes use of a velocity.properties file to resolve templates
>> (*.vm files) as Velocity engine does: considers relative paths defined
>> by file.resource.loader.path property to find template files.
>>
>> How does your Velocity engine resolve a file in a dependant JAR in a
>> Vm file? Can you provide more info about those files?
>>
>> BR,
>> Alexey
>>
>> nodje wrote:
>>> Hi Alexey,
>>>
>>> so isn't it a problem that IDEA's resolution proposal introduce
>>> a@velocityproperties statement?
>>> I don't see where the velocity.properties could help in resolving a
>>> file's location.
>>>
>>> Is there a way to help IDEA resolve a file in a dependant JAR in a Vm
>>> file?
>>>
>>> rgds,
>>> nodje
>>>
>>> On 2009-11-30 21:57:33 +0900, Alexey Chmutov
>>> <achmutov@swiftteams.com> said:
>>>
>>>> Hi nodje
>>>>
>>>> @velocityproperties comment is useful only if there is some
>>>> velocity.properties file in your project.
>>>>
>>>> for more info, see
>>>> http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/
>>>>


BR,

Alexey

nodje

>>>>
>>>> wrote:
>>>>> I use Velocity templates for HTML mail templates in a Java
>>>>> application.
>>>>>
>>>>> It includes a common template with #parse:
>>>>>
>>>>> #parse( "defaultMailTemplate.vm" )
>>>>>
>>>>> Idea cannot resolve it and proposed to use @velocityproperties
>>>>>
>>>>> It's my first time using this, I can't find any reference to it in
>>>>> the help.
>>>>>
>>>>> I've tried this but to no avail:
>>>>> #* @velocityproperties path=classpath:defaultMailTemplate.vm *#
>>>>>
>>>>> the defaultMailTemplate.vm in question is at the root of a JAR
>>>>> dependency.
>>>>>
>>>>> Is there a way to resolve a file located in a JAR with
>>>>> @velocityproperties ?
>>>>>
>>>>> I'm using #92.65
>>>>>
>>>>> ---
>>>>> Original message URL:
>>>>> http://www.jetbrains.net/devnet/message/5251219#5251219


0
Comment actions Permalink

That's right Alexey, my config is exactly as you describe.
I was happily surprised to see this working flawlessly right from start.

On 2009-12-02 22:45:51 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:

Hi nodje

You shouldn't modify you velocity.properties file just to help IDEA
resolve template files. The resolve should work in natural conditions
:). Moreover, the changing of the file won't help.
To ensure I get it right, let me describe your configuration:

There are a vm-file with a line #parse( "defaultMailTemplate.vm" )
and a jar-file containng defaultMailTemplate.vm,
and you just run Velocity engine with that jar-file in classpath?

nodje wrote:

>> Hi Alexey,
>>
>> I've got a velocity.properties of course. I put it in
>> src/main/webapp/WEB-INF/ .
>> I can't remember why I've chosen WEB-INF rather than
>> src/main/resources, but I remember it was a conscious choice, I've
>> unified all our application in this fashion.
>>
>> I was lucky enough I had nothing to change to have Velocity resolve Vm
>> files in dependant JARs.
>> I've got no file.resource.loader.path property specified in
>> Velocity.properties, so the default value is in use I suppose.
>> Looking into Velocity jars I can't find any default though.
>> The only reference to "file.resource.loader.path" I can find is in
>> spring-context-support.jar
>>
>> Are you saying setting "file.resource.loader.path" in the
>> velocity.properties woud have IDEA alos resolve the Vm files in the
>> classpath?
>> I'd be reluctant to do that since everything works fine without, but if
>> it has not impact, why not.
>>
>> -nodje
>>
>> On 2009-12-01 19:52:22 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:
>>
>>> Hi nodje
>>>
>>> Actually, a problem is that @velocityproperties intention is active
>>> when no velocity.properties file found. (Your project doesn't contain
>>> any velocity.properties file, right?)
>>> IDEA makes use of a velocity.properties file to resolve templates (*.vm
>>> files) as Velocity engine does: considers relative paths defined by
>>> file.resource.loader.path property to find template files.
>>>
>>> How does your Velocity engine resolve a file in a dependant JAR in a Vm
>>> file? Can you provide more info about those files?
>>>
>>> BR,
>>> Alexey
>>>
>>> nodje wrote:
>>>> Hi Alexey,
>>>>
>>>> so isn't it a problem that IDEA's resolution proposal introduce
>>>> a@velocityproperties statement?
>>>> I don't see where the velocity.properties could help in resolving a
>>>> file's location.
>>>>
>>>> Is there a way to help IDEA resolve a file in a dependant JAR in a Vm file?
>>>>
>>>> rgds,
>>>> nodje
>>>>
>>>> On 2009-11-30 21:57:33 +0900, Alexey Chmutov <achmutov@swiftteams.com> said:
>>>>
>>>>> Hi nodje
>>>>>
>>>>> @velocityproperties comment is useful only if there is some
>>>>> velocity.properties file in your project.
>>>>>
>>>>> for more info, see
>>>>> http://blogs.jetbrains.com/idea/2009/08/enabling-template-files-and-velocimacros-resolution/

BR,

Alexey

nodje

wrote:
I
>>>>>
>>>>>> use Velocity templates for HTML mail templates in a Java application.
>>>>>>
>>>>>> It includes a common template with #parse:
>>>>>>
>>>>>> #parse( "defaultMailTemplate.vm" )
>>>>>>
>>>>>> Idea cannot resolve it and proposed to use @velocityproperties
>>>>>>
>>>>>> It's my first time using this, I can't find any reference to it in the help.
>>>>>>
>>>>>> I've tried this but to no avail:
>>>>>> #* @velocityproperties path=classpath:defaultMailTemplate.vm *#
>>>>>>
>>>>>> the defaultMailTemplate.vm in question is at the root of a JAR dependency.
>>>>>>
>>>>>> Is there a way to resolve a file located in a JAR with @velocityproperties ?
>>>>>>
>>>>>> I'm using #92.65
>>>>>>
>>>>>> ---
>>>>>> Original message URL: http://www.jetbrains.net/devnet/message/5251219#5251219


0
Comment actions Permalink

nodje,

I've played in my sandbox (it consists of vm-file, jar-file containing
other vm-file and this jar-file metioned in classpath) and my Velocity
engine cannot resolve vm-file in jar.
So, provide please working example of your config.

BR, Alexey

nodje wrote:

That's right Alexey, my config is exactly as you describe.
I was happily surprised to see this working flawlessly right from start.

On 2009-12-02 22:45:51 +0900, Alexey Chmutov <achmutov@swiftteams.com>
said:

>> Hi nodje
>>
>> You shouldn't modify you velocity.properties file just to help IDEA
>> resolve template files. The resolve should work in natural conditions
>> :). Moreover, the changing of the file won't help.
>> To ensure I get it right, let me describe your configuration:
>>
>> There are a vm-file with a line #parse( "defaultMailTemplate.vm" )
>> and a jar-file containng defaultMailTemplate.vm,
>> and you just run Velocity engine with that jar-file in classpath?
>>

0
Comment actions Permalink

Hi Alexey,

sorry it took me a while to come up with a working example. We were releasing.

Basically it works without any Velocity configuration, except force it to use org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader as Class loader.

The example is made of a common.jar project and a "webapp" velocity.war.
You just need to 'mvn install' the common.jar then run the VelocityTest in the velocity project.

rgds,
nodje



Attachment(s):
velocity-test.zip
0
Comment actions Permalink

nodje, thanks for the sample.
I'll learn it and think out how to support it

nodje wrote:

Hi Alexey,

sorry it took me a while to come up with a working example. We were releasing.

Basically it works without any Velocity configuration, except force it to use org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader as Class loader.

The example is made of a common.jar project and a "webapp" velocity.war.
You just need to 'mvn install' the common.jar then run the VelocityTest in the velocity project.

rgds,
nodje

---
Original message URL: http://www.jetbrains.net/devnet/message/5252776#5252776

0

Please sign in to leave a comment.