|Creating files based on templates [message #1169555]
||Sun, 03 November 2013 22:42
| Eli B
Registered: November 2013
So I'm a Java developer, taking a stab at developing an eclipse plugin for the first time. I have a basic new project wizard running. Now say I want it to generate a couple files for me on performFinish with some default text, can someone point in the right direction for how to do that? I can't imagine the right approach would be to store the text in a file and use the File API to read it in, is it?
|Re: Creating files based on templates [message #1173625 is a reply to message #1172137]
||Wed, 06 November 2013 11:53
|| Mickael Istria
Registered: July 2009
Location: Grenoble, France
On 11/05/2013 07:29 PM, Ilya B wrote:|
> Where do I store this 10 lines of code?
Where you want: as a static string, as a resource file in the bundle, as
a preference value, somewhere over HTTP... It really depends on your
> I'd imagine that it should go in some kind of separate template file,
> say dslHelloWorld.template. But, how do I bundle this with my plug-in so
> that the custom new project wizard knows about it and can put this
> template file in with the new project?
Anyway, you'll need to write the code that create the IFile with the
given content in the performFinish method. There is no automatic
behaviour to create a file at the end of a wizard.
When it comes to getting content, assuming you've created this file as a
resource in your bundle, the right way to do it is to use
getClass().getResourceAsStream("/myTemplateFile") if the resource is
available in your classloader.
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Powered by FUDForum
. Page generated in 0.01765 seconds