You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "EXTERNAL Shakirov Timur (ISS; GS-EC/EMT2)" <ex...@de.bosch.com> on 2005/08/30 17:00:40 UTC

Problem by using an Absolute Path to template in Windows

Hello,

I'm using Velocity v.1.4 in my Eclipse-Plug-in application to generate
some files. To be able to use Velocity in Eclipse Plug-in I have had to
wrap it also into a form of an Eclipse Plain - not a big deal. And it
works.

The only problem I have is that than I'm trying to use an absolute path
to .vm-file in the method Velocity.getTemplate() I get an error message
like this: 

org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource 'C:\test\velogen\test.vm'
	at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Re
sourceManagerImpl.java:458)
	at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Res
ourceManagerImpl.java:341)
	at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
java:831)
	at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
java:813)
	at
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleto
n.java:285)
	at
org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)
	at
com.bosch.de.velogen.gui.MainDialog.okPressed(MainDialog.java:187)
	at
org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:409)
	at
org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:556)
	at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
	at
org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
	at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3080)
	at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:809)
	at org.eclipse.jface.window.Window.open(Window.java:787)
	at
com.bosch.de.velogen.actions.VelocityGeneratorAction.run(VelocityGenerat
orAction.java:35)
	at
org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:246)
	at
org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.j
ava:223)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(Ac
tionContributionItem.java:538)
	at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContribut
ionItem.java:488)
	at
org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionCont
ributionItem.java:441)
	at
org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
	at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3080)
	at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
	at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
	at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:3
67)
	at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at
org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActiva
tor.java:226)
	at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
376)
	at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
163)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
	at org.eclipse.core.launcher.Main.run(Main.java:973)
	at org.eclipse.core.launcher.Main.main(Main.java:948)

Is it possible to use absolute path to template as a parameter of the
function Velocity.getTemplate()?
If yes, how could I do that? If not, how could I set a root folder for
Velocity Resource Manager to use relative paths to velocity macros or is
any other workaround for this problem?

I'm using an empty velocity.properties-file.

Code snippet:
-----------------------------------------

OutputStream os = new FileOutputStream( "c:\test\velogen\hello.txt" );
OutputStreamWriter writer = writer = new OutputStreamWriter( os );

Velocity.init( "c:\test\velogen\velocity.properties" ); // runtime.log =
velocity_example.log
VelocityContext context = new VelocityContext();
Template template = null;

String templateFileName = "c:\test\velogen\test.vm" ;
try
{
	template = Velocity.getTemplate( templateFileName ); //This line
produce an exception
	if ( template != null )
	{
		template.merge( context, writer );
	}
	writer.flush();
	writer.close();
}
catch( Exception e) 
{
...
}

Regards,
Tim
 
Timur Shakirov

============================================================
Robert Bosch GmbH
(iss GmbH)
Dept. GS-EC/EMT2
Robert Bosch Str. 2
D-71701 Schwieberdingen
Germany 
Phone: +49 (711) 811-34950
E-Mail: external.timur.shakirov@de.bosch.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org