You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <gm...@xyris.com> on 2001/09/25 18:04:54 UTC

RE: Putting an application using Velocity in a jar file: How do you do it?

 From: Tommy Svensson [mailto:tommy.svensson@askus.se]

> Hello,
> I have two things I want to do with an application/tool I'm writing:
> 1.Use Velocity.

Good!

> 2.Put my application/tool in a jar file to be run with java -jar.
> As I have understood from the documentation this would be
> very difficult
> since there seem to be no nice way to get templates also
> stored in the
> jar file. The JarResourceLoader wont help me since I would
> have to know
> where the user put the jar file in his/her filesystem. The
> FileResourceLoader is of course out of the question unless I
> force the
> user to unpack the jar file and then specify where he/she
> unpacked it.
> This would also be unacceptable. The ClasspathResourceLoader might
> actually do it, but it forces me to create a WEB-INF/lib
> catalog to put
> the templates in.

No, it doesn't.  It should take from the classpath, so putting them in the
appliation jar should work.  I am sorry if the documentation led you to
beleive this - it will be corrected.

> I don't like this since my app doesn't really have
> anything to do with the web (well, it does produce html, but as a
> documentation format only. Its a C++ javadoc type tool), and
> WEB-INF/lib
> feel very wrong then. Maybe I'm a bit picky, but I would
> prefer to have
> my templates under resources/templates if possible. I guess I could
> compromise and use WEB-INF/lib/resources/templates if the
> ClasspathResourceLoader does the job.
> Is there any "nicer" way to get to templates in my jar file ? Like:
> Tempate templ =
> (Template)this.getClass().getResource("../resources/templates/
> mytemplate
> .vm");
> If I have missunderstood the use of any of the
> ResourceLoaders mentioned
> above, please correct me.
> I'm sorry if I'm sounding a bit negative. I'm very impressed with
> Velocity. It seems a much nicer and cleaner solution than JSP for
> servlets by letting the application feed the gui instead of the gui
> fetching from the applicaiton.

No worries - it should work fine with the ClasspathResourceLoader with the
templates within the jar.

geir



Re: Putting an application using Velocity in a jar file: How doyoudo it?

Posted by Alexander Pokahr <5p...@informatik.uni-hamburg.de>.
>> Some discussion on this topic can be found here:
>> http://developer.java.sun.com/developer/bugParade/bugs/4356783.html
> 
> This link seems dead. Is the -jar option buggy ?


You have to be logged in to the developer connection,
to access the bug database:
http://developer.java.sun.com/developer/?frontpage-main


No, the -jar option is not buggy. But the evaluation section
offers a nice description of why it is implemented that way:


Synopsis:   Running java.exe with "-jar" ignores the classpath
State:      Closed, will not be fixed

Evaluation:
This feature request (not bug) could be implemented fairly trivially,
but would create backward compatibility issues.  In particular, users
who were (perhaps unknowingly) depending on their classpath NOT
interfering, could see new failures.  This is adequate reason to reject
the change request.


This sounds similar to what Geir mentioned.



Alex


Re: Putting an application using Velocity in a jar file: How do youdo it?

Posted by Tommy Svensson <to...@askus.se>.
> Citing from  the description of the -jar option in
> http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.html

> "When you use this option, the JAR file is the source of all user 
classes,
> and other user class path settings are ignored."

> So Velocity can't be found, if it's in the CLASSPATH.
> The location of the velocity.jar has to be specified in the manifest 
file.

Yes, that is right, I almost forgot! I've experienced problems with this 
before.
I like to support the -jar option when I can since it makes it easier for 
the
user. 

> Some discussion on this topic can be found here:
> http://developer.java.sun.com/developer/bugParade/bugs/4356783.html

This link seems dead. Is the -jar option buggy ?

/Tommy


Re: Putting an application using Velocity in a jar file: How do youdo it?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/26/01 5:47 AM, "Alexander Pokahr" <5p...@informatik.uni-hamburg.de>
wrote:

> Hi Tommy,
> 
> Tommy Svensson wrote:
>> 
>> That brings me to another question: Is it OK to include Velocity.jar in
>> my jar file and add a Class-path to it, so that my tool will contain a
>> private copy of Velocity ? Or do the users of my tool have to download
>> Velocity separately and make it available in the CLASSPATH ? This being
>> open source I suspect it is OK to include it. My tool is not comercial
>> and will be available for free with source code.
> 
> 
> Citing from  the description of the -jar option in
> http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.html
> 
> "When you use this option, the JAR file is the source of all user classes,
> and other user class path settings are ignored."
> 
> So Velocity can't be found, if it's in the CLASSPATH.
> The location of the velocity.jar has to be specified in the manifest file.
> 

That's resolves my concerns about collisions between the users classpath and
the jar... :)


> 
> Some discussion on this topic can be found here:
> http://developer.java.sun.com/developer/bugParade/bugs/4356783.html
> 
> 
> Alex

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



Re: Putting an application using Velocity in a jar file: How do youdo it?

Posted by Alexander Pokahr <5p...@informatik.uni-hamburg.de>.
Hi Tommy,

Tommy Svensson wrote:
> 
> That brings me to another question: Is it OK to include Velocity.jar in
> my jar file and add a Class-path to it, so that my tool will contain a
> private copy of Velocity ? Or do the users of my tool have to download
> Velocity separately and make it available in the CLASSPATH ? This being
> open source I suspect it is OK to include it. My tool is not comercial
> and will be available for free with source code.


Citing from  the description of the -jar option in
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.html

"When you use this option, the JAR file is the source of all user classes,
and other user class path settings are ignored."

So Velocity can't be found, if it's in the CLASSPATH.
The location of the velocity.jar has to be specified in the manifest file.


Some discussion on this topic can be found here:
http://developer.java.sun.com/developer/bugParade/bugs/4356783.html


Alex

RE: Putting an application using Velocity in a jar file: How do you do it?

Posted by Tommy Svensson <to...@askus.se>.
Hello again,

>  From: Tommy Svensson [mailto:tommy.svensson@askus.se]

> > Hello,
> > I have two things I want to do with an application/tool I'm writing:
> > 1.Use Velocity.

> Good!

> > 2.Put my application/tool in a jar file to be run with java -jar.
> > As I have understood from the documentation this would be
> > very difficult
> > since there seem to be no nice way to get templates also
> > stored in the
> > jar file. The JarResourceLoader wont help me since I would
> > have to know
> > where the user put the jar file in his/her filesystem. The
> > FileResourceLoader is of course out of the question unless I
> > force the
> > user to unpack the jar file and then specify where he/she
> > unpacked it.
> > This would also be unacceptable. The ClasspathResourceLoader might
> > actually do it, but it forces me to create a WEB-INF/lib
> > catalog to put
> > the templates in.

> No, it doesn't.  It should take from the classpath, so putting them in 
the
> appliation jar should work.  I am sorry if the documentation led you to
> beleive this - it will be corrected.

I have read the docs again, and I see my misstake. The doc example says 
that you should put the templates in a jar file and put that jar file in 
WEB-INF/lib. It doesn't say the templates should be put directly in 
WEB-INF/lib! I have played with servlets, and created war files, and as I 
remember any jar file in WEB-INF/lib is added to the classpath, so this 
example basically says that the templates should be made available in the 
classpath, though it could be clarified somewhat ;-). Simply adding a 
sentence like “The ClasspathResourceLoader will simply load templates 
from anywhere in the classpath.” would help.

I have realized that I should probably put my templates in a separate jar 
file, and include that jar file in my “executable” jar file. As I 
remember you can put a “Class-path:” tag in the MANIFEST.MF file to add 
“inner” jar files to the classpath. 

That brings me to another question: Is it OK to include Velocity.jar in 
my jar file and add a Class-path to it, so that my tool will contain a 
private copy of Velocity ? Or do the users of my tool have to download 
Velocity separately and make it available in the CLASSPATH ? This being 
open source I suspect it is OK to include it. My tool is not comercial 
and will be available for free with source code. 

/Tommy

> > I don't like this since my app doesn't really have
> > anything to do with the web (well, it does produce html, but as a
> > documentation format only. Its a C++ javadoc type tool), and
> > WEB-INF/lib
> > feel very wrong then. Maybe I'm a bit picky, but I would
> > prefer to have
> > my templates under resources/templates if possible. I guess I could
> > compromise and use WEB-INF/lib/resources/templates if the
> > ClasspathResourceLoader does the job.
> > Is there any "nicer" way to get to templates in my jar file ? Like:
> > Tempate templ =
> > (Template)this.getClass().getResource("../resources/templates/
> > mytemplate
> > .vm");
> > If I have missunderstood the use of any of the
> > ResourceLoaders mentioned
> > above, please correct me.
> > I'm sorry if I'm sounding a bit negative. I'm very impressed with
> > Velocity. It seems a much nicer and cleaner solution than JSP for
> > servlets by letting the application feed the gui instead of the gui
> > fetching from the applicaiton.

> No worries - it should work fine with the ClasspathResourceLoader with 
the
> templates within the jar.

> geir