You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rambo Mahajan <ra...@yahoo.com> on 2005/09/27 01:05:16 UTC
ant variable
Hi
I am using FileResourceLoader to initialize VelocityEngine in Java file as follows:
Properties props = new Properties();
props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class", FileResourceLoader.class.getName());
props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path", ANT_VAR);
engine.init(props);
I would like to know how to access ant variable ANT_VAR inside Java code ?
Thanks
Ram
---------------------------------
Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.
Re: Rethrowing in a toolbox class
Posted by Nathan Bubna <nb...@gmail.com>.
though i haven't used it myself, i believe this problem is meant to be
handled by the MethodExceptionEventHandler. see
http://jakarta.apache.org/velocity/docs/developer-guide.html#EventCartridge%20and%20Event%20Handlers
for more on using it.
On 9/27/05, Christophe <an...@yahoo.fr> wrote:
> Hello, I wonder if there is a way for me to see the stacktrace when an
> exception occurs in a classes declared to be used by toolbox.xml
>
> For example :
> public HashMap daysOfMonth(String dateString) throws Exception
> {
> log.debug("Date to parse is " + dateString);
> HashMap days = new HashMap();
> Date date = df.parse(dateString);
> cal.setTime(date);
> int d;
> for(d=1;d <= cal.getActualMaximum(Calendar.DAY_OF_MONTH);d++)
> {
> cal.set(Calendar.DAY_OF_MONTH,d);
> log.debug("Value = " + cal.get(Calendar.DAY_OF_WEEK ) +
> " d=" + d);
> String ds = daysNames[cal.get(Calendar.DAY_OF_WEEK ) - 1];
> days.put(new Integer(d),ds);
> }
> return days;
>
> I declared the function with throws Exception because a parse exception
> can occur, but when it's throwed I don't have any way to see the stack
> trace in the logs...
> There's only one line in the logs : Method daysOfMonth threw exception
> for reference $DateTool in template /templates/event_form.vm at [18,9]
>
> Thanks
>
>
>
>
>
> ___________________________________________________________________________
> Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
> Téléchargez cette version sur http://fr.messenger.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Rethrowing in a toolbox class
Posted by Christophe <an...@yahoo.fr>.
Hello, I wonder if there is a way for me to see the stacktrace when an
exception occurs in a classes declared to be used by toolbox.xml
For example :
public HashMap daysOfMonth(String dateString) throws Exception
{
log.debug("Date to parse is " + dateString);
HashMap days = new HashMap();
Date date = df.parse(dateString);
cal.setTime(date);
int d;
for(d=1;d <= cal.getActualMaximum(Calendar.DAY_OF_MONTH);d++)
{
cal.set(Calendar.DAY_OF_MONTH,d);
log.debug("Value = " + cal.get(Calendar.DAY_OF_WEEK ) +
" d=" + d);
String ds = daysNames[cal.get(Calendar.DAY_OF_WEEK ) - 1];
days.put(new Integer(d),ds);
}
return days;
I declared the function with throws Exception because a parse exception
can occur, but when it's throwed I don't have any way to see the stack
trace in the logs...
There's only one line in the logs : Method daysOfMonth threw exception
for reference $DateTool in template /templates/event_form.vm at [18,9]
Thanks
___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez cette version sur http://fr.messenger.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: ant variable
Posted by Will Glass-Husain <wg...@forio.com>.
You could have ant write to a text properties file and let the Java code
read from it?
It's an unusual case though for a path to be generated at compile time.
You might have an easier time using ClasspathResourceLoader and just
sticking the templates in your jar files.
WILL
----- Original Message -----
From: "Rambo Mahajan" <ra...@yahoo.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, September 26, 2005 4:54 PM
Subject: Re: ant variable
> Well, I am working on a web application and I use Ant to build war and ear
> files. I have a Java file where I configure VelocityEngine as follows:
>
> public class Emailer {
> VelocityEngine engine = new VelocityEngine();
> public Emailer() throws Exception{
> configure(engine);
> }
>
> public configure(VelocityEnfine engine){
> Properties props = new Properties();
> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
> FileResourceLoader.class.getName());
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
> ANT_VAR);
> engine.init(props);
> }
>
>
> }
>
> I am looking for what should I substitute for ANT_VAR if I have following
> variable defined in build.properties:
>
> xyz.config.dir=${xyz.base.dir}/config
>
>
> Thanks
> Ram
>
> Will Glass-Husain <wg...@forio.com> wrote:
> Where does Ant come into the picture?
>
> Does ant launch the java code that uses VelocityEngine? Or have you
> written
> an ant task that uses VelocityEngine?
>
> Or is the path just sitting in an "build.xml" file but ant is never run?
>
> WILL
>
> ----- Original Message -----
> From: "Rambo Mahajan"
> To: "Velocity Users List"
> Sent: Monday, September 26, 2005 4:39 PM
> Subject: Re: ant variable
>
>
>> actually, no ...
>>
>> I am calling VelocityEngine inside Java code. In this case how should I
>> set file resource loader's path by a variable defined in Ant build file ?
>>
>> Thanks
>> Ram
>>
>> Will Glass-Husain wrote:
>> Are you calling Velocity with the tag in an ant class?
>>
>> If so, I'd set a System property.
>>
>> WILL
>>
>> ----- Original Message -----
>> From: "Rambo Mahajan"
>> To:
>> Sent: Monday, September 26, 2005 4:05 PM
>> Subject: ant variable
>>
>>
>>> Hi
>>>
>>> I am using FileResourceLoader to initialize VelocityEngine in Java file
>>> as
>>> follows:
>>>
>>> Properties props = new Properties();
>>> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
>>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
>>> FileResourceLoader.class.getName());
>>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
>>> ANT_VAR);
>>> engine.init(props);
>>>
>>> I would like to know how to access ant variable ANT_VAR inside Java code
>>> ?
>>>
>>> Thanks
>>> Ram
>>>
>>>
>>> ---------------------------------
>>> Yahoo! for Good
>>> Click here to donate to the Hurricane Katrina relief effort.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>
>> ---------------------------------
>> Yahoo! for Good
>> Click here to donate to the Hurricane Katrina relief effort.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: ant variable
Posted by Rambo Mahajan <ra...@yahoo.com>.
Well, I am working on a web application and I use Ant to build war and ear files. I have a Java file where I configure VelocityEngine as follows:
public class Emailer {
VelocityEngine engine = new VelocityEngine();
public Emailer() throws Exception{
configure(engine);
}
public configure(VelocityEnfine engine){
Properties props = new Properties();
props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
FileResourceLoader.class.getName());
props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
ANT_VAR);
engine.init(props);
}
}
I am looking for what should I substitute for ANT_VAR if I have following variable defined in build.properties:
xyz.config.dir=${xyz.base.dir}/config
Thanks
Ram
Will Glass-Husain <wg...@forio.com> wrote:
Where does Ant come into the picture?
Does ant launch the java code that uses VelocityEngine? Or have you written
an ant task that uses VelocityEngine?
Or is the path just sitting in an "build.xml" file but ant is never run?
WILL
----- Original Message -----
From: "Rambo Mahajan"
To: "Velocity Users List"
Sent: Monday, September 26, 2005 4:39 PM
Subject: Re: ant variable
> actually, no ...
>
> I am calling VelocityEngine inside Java code. In this case how should I
> set file resource loader's path by a variable defined in Ant build file ?
>
> Thanks
> Ram
>
> Will Glass-Husain wrote:
> Are you calling Velocity with the tag in an ant class?
>
> If so, I'd set a System property.
>
> WILL
>
> ----- Original Message -----
> From: "Rambo Mahajan"
> To:
> Sent: Monday, September 26, 2005 4:05 PM
> Subject: ant variable
>
>
>> Hi
>>
>> I am using FileResourceLoader to initialize VelocityEngine in Java file
>> as
>> follows:
>>
>> Properties props = new Properties();
>> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
>> FileResourceLoader.class.getName());
>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
>> ANT_VAR);
>> engine.init(props);
>>
>> I would like to know how to access ant variable ANT_VAR inside Java code
>> ?
>>
>> Thanks
>> Ram
>>
>>
>> ---------------------------------
>> Yahoo! for Good
>> Click here to donate to the Hurricane Katrina relief effort.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Yahoo! for Good
> Click here to donate to the Hurricane Katrina relief effort.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: ant variable
Posted by Will Glass-Husain <wg...@forio.com>.
Where does Ant come into the picture?
Does ant launch the java code that uses VelocityEngine? Or have you written
an ant task that uses VelocityEngine?
Or is the path just sitting in an "build.xml" file but ant is never run?
WILL
----- Original Message -----
From: "Rambo Mahajan" <ra...@yahoo.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, September 26, 2005 4:39 PM
Subject: Re: ant variable
> actually, no ...
>
> I am calling VelocityEngine inside Java code. In this case how should I
> set file resource loader's path by a variable defined in Ant build file ?
>
> Thanks
> Ram
>
> Will Glass-Husain <wg...@forio.com> wrote:
> Are you calling Velocity with the tag in an ant class?
>
> If so, I'd set a System property.
>
> WILL
>
> ----- Original Message -----
> From: "Rambo Mahajan"
> To:
> Sent: Monday, September 26, 2005 4:05 PM
> Subject: ant variable
>
>
>> Hi
>>
>> I am using FileResourceLoader to initialize VelocityEngine in Java file
>> as
>> follows:
>>
>> Properties props = new Properties();
>> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
>> FileResourceLoader.class.getName());
>> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
>> ANT_VAR);
>> engine.init(props);
>>
>> I would like to know how to access ant variable ANT_VAR inside Java code
>> ?
>>
>> Thanks
>> Ram
>>
>>
>> ---------------------------------
>> Yahoo! for Good
>> Click here to donate to the Hurricane Katrina relief effort.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Yahoo! for Good
> Click here to donate to the Hurricane Katrina relief effort.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: ant variable
Posted by Rambo Mahajan <ra...@yahoo.com>.
actually, no ...
I am calling VelocityEngine inside Java code. In this case how should I set file resource loader's path by a variable defined in Ant build file ?
Thanks
Ram
Will Glass-Husain <wg...@forio.com> wrote:
Are you calling Velocity with the tag in an ant class?
If so, I'd set a System property.
WILL
----- Original Message -----
From: "Rambo Mahajan"
To:
Sent: Monday, September 26, 2005 4:05 PM
Subject: ant variable
> Hi
>
> I am using FileResourceLoader to initialize VelocityEngine in Java file as
> follows:
>
> Properties props = new Properties();
> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
> FileResourceLoader.class.getName());
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
> ANT_VAR);
> engine.init(props);
>
> I would like to know how to access ant variable ANT_VAR inside Java code ?
>
> Thanks
> Ram
>
>
> ---------------------------------
> Yahoo! for Good
> Click here to donate to the Hurricane Katrina relief effort.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
---------------------------------
Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.
Re: ant variable
Posted by Will Glass-Husain <wg...@forio.com>.
Are you calling Velocity with the <java> tag in an ant class?
If so, I'd set a System property.
WILL
----- Original Message -----
From: "Rambo Mahajan" <ra...@yahoo.com>
To: <ve...@jakarta.apache.org>
Sent: Monday, September 26, 2005 4:05 PM
Subject: ant variable
> Hi
>
> I am using FileResourceLoader to initialize VelocityEngine in Java file as
> follows:
>
> Properties props = new Properties();
> props.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".class",
> FileResourceLoader.class.getName());
> props.setProperty("file." + VelocityEngine.RESOURCE_LOADER + ".path",
> ANT_VAR);
> engine.init(props);
>
> I would like to know how to access ant variable ANT_VAR inside Java code ?
>
> Thanks
> Ram
>
>
> ---------------------------------
> Yahoo! for Good
> Click here to donate to the Hurricane Katrina relief effort.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org